Вы можете мне помочь?
У меня есть два файла .txt с различиями между ними, и мне нужно сравнить их и сказать, в чем разница и где она.
Я сделал простой код, но все еще не ответил мне.
File1:
123
1234
12345
123456
1234567
12345678
123456789
1234567890
saída do arquivo
File2:
123
1234
12345
123456
1234567
12345678
123456789
1234567890
fim de arquivo
Программа должна вернуть:
File1: saída do arquivo - line 9
File2: fim de arquivo - line 9
Мой код:
test_lines = open('teste1.txt').readlines()
correct_lines = open('teste2.txt').readlines()
for test, correct in zip(test_lines, correct_lines):
if test != correct:
print (("Oh no! Expected %r; got %r." )% (correct, test));
break
else:
len_diff = len(test_lines) - len(correct_lines)
if len_diff > 0:
print ("Test file had too much data.")
elif len_diff < 0:
print ("Test file had too little data.")
else:
print ("Everything was correct!")
lista_final = list(set(test_lines) - set(correct_lines))
print(lista_final)
Что на самом деле возвращает:
['12345\t\t\t\n', '123456\n', 'saída do arquivo']