file_name=input("请输入想打开的文件名:")
f=open("E:\python\"+file_name,encoding='UTF8')
file_name2=input("请输入需要比较的文件名:")
f1=open("E:\python\"+file_name2,encoding='UTF8')
num_line1=0
num_line2=0
dict1={}
dict2={}
for each_line in f:
num_line1+=1
dict1[num_line1]=each_line
for each_line1 in f1:
num_line2+=1
dict2[num_line2]=each_line1
num_line=1
differences=0
differences_index=[]
while num_line<num_line1 or num_line<num_line2:
if dict1[num_line]!=dict2[num_line]:
differences+=1
differences_index.append(num_line)
else:
continue
num_line+=1
print("这两个文件共有",differences,"个不同")
print("其中",differences_index,"行不同。")