Question

I have a script to generate files with python, in some cases, the script is executed with the python of in windows and in other cases with the python of cygwin

the text of the files is the same but if I use difflib,

gen_file_data = open(gen_file)
base_file_data = open(base_file)
gen_file_content = gen_file_data.read().splitlines(True)
base_file_content = base_file_data.read().splitlines(True)
gen_file_data.close()
base_file_data.close()
diff = difflib.unified_diff(gen_file_content, base_file_content, n=0)
diff = ''.join(diff)

the files are different.

And, if I use md5 get diferent hash.

import hashlib
base_md5 = hashlib.md5(base_file_content).hexdigest()
gen_md5 = hashlib.md5(gen_file_content).hexdigest()
print gen_md5, base_md5

If I compare the files with kdiff3 I get

Files A and B have equal text, but are not binary equal.

how I can comparate the text diferences between two files?, one generated with python of windows and other generated with python of windows.

Was it helpful?

Solution

The issue is likely end-of-line encoding. Windows uses '\r\n', whereas unix (which cygwin emulates) uses '\n'

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top