I'm trying to diff between 2 files in python
I tried using this code:
with open(file_1, "r") as file1:
with open(file_2, "r") as file2:
diff = set(file1).difference(file2)
with open(file_o, "w") as file_out:
for line in diff:
file_out.write(line)
file_out.close()
if os.path.getsize(file_o) == 0:
print "match"
else:
print "does not match"
But I'm facing an issue using it, it does not work for all files!!
This is totally weird, any idea why ? and how can I fix it?
if there is any very fast way for diffing 2 files without being sensitive to line order, would be thankful
Thanks
Do give us more input as to why it doesn't work. Off the top of my head, looking at your code the comparison to see if the file is open or not is plain risky. The inode for the file could have a size even though it is empty. If you want, what you could do is check if diff is empty, rather than the file, that would make for a better comparison.