1with open('some_file_1.txt', 'r') as file1:
2 with open('some_file_2.txt', 'r') as file2:
3 same = set(file1).intersection(file2)
4
5same.discard('\n')
6
7with open('some_output_file.txt', 'w') as file_out:
8 for line in same:
9 file_out.write(line)
1import difflib
2import sys
3
4# git-styled output
5
6with open('/tmp/hosts0', 'r') as hosts0:
7 with open('/tmp/hosts1', 'r') as hosts1:
8 diff = difflib.unified_diff(
9 hosts0.readlines(),
10 hosts1.readlines(),
11 fromfile='hosts0',
12 tofile='hosts1',
13 )
14 for line in diff:
15 sys.stdout.write(line)