I have small script that compares files
import filecmp
filecmp.cmp(path1, path2)
This code returns True if files are similar
But it returns False in case when newline are different. path1 have Linux newline and path2 have Windows newline.
I want get True in case if files differs only with newline character.
Is it possible without editing files?
This is not possible to do with the filecmp module as it can only use stat to compare files and won't let you override the comparison.
You could do something with itertools as noted here:
from itertools import izip
def areFilesIdentical(filename1, filename2):
with open(filename1, "rtU") as a:
with open(filename2, "rtU") as b:
# Note that "all" and "izip" are lazy
# (will stop at the first line that's not identical)
return all(myprint() and lineA == lineB
for lineA, lineB in izip(a, b))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With