Compare two files
from difflib import ndiff f1 = open('file1.txt').read().splitlines(True) f2 = open('file2.txt').read().splitlines(True) diff = ndiff(f1 , f2) print(''.join(diff)) In the result I get all the lines - the same and different. How can I display only different / missing / new lines in the result? Those. Do not display the same data in both files.
.splitlines(keepends=True)more readable than.splitlines(True)- jfs