문제

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.

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top