I'm trying to compare two .txt files in order to observe the changes have been done before. these files contains of list informations, you can see them below. If last 4 elements are exactly same, then the function doesn't print them on the screen but I'd like to see all the information to check if its changed, added or deleted.
Here's my code
import difflib
def compare_text_files(file1, file2):
with open(file1, 'r') as f1, open(file2, 'r') as f2:
text1 = f1.readlines()
text2 = f2.readlines()
differ = difflib.Differ()
diff = list(differ.compare(text1, text2))
diff = list(difflib.context_diff(text1, text2))
return diff
if __name__ == '__main__':
file1 = 'test1.txt'
file2 = 'test2.txt'
differences = compare_text_files(file1, file2)
for line in differences:
print(line)`
and the test files: test1.txt A1: blu B1: yellow C3: red D6: green E5: white F9: grey H8: black A2: turuncu
tes2.txt A1: blue B1: yellow C3: red D6: green E5: white F9: grey H8: black A2: turuncu