I need to compare two files and redirect the different lines to third file. I know using diff command i can get the difference . But, is there any way of doing it in python ? An
import sys
if len(sys.argv) !=3 :
print "usage:" + sys.argv[0] + " bla bla"
exit
elif len(sys.argv) == 3:
file1 = set((x for x in open(sys.argv[1])))
file2 = set((x for x in open(sys.argv[2])))
file3 = file2.difference(file1)
file4 = file1.difference(file2)
str1="file1-contains but file2 not \n"
str2="file2-contains but file1 not\n"
FILE = open('file3','w')
FILE.writelines(str2)
FILE.writelines(file3)
FILE.writelines(str1)
FILE.writelines(file4)