How should I compare two txt files separately coming from windows/dos and linux/unix

higer higerinbeijing at gmail.com
Wed Jun 10 23:11:50 EDT 2009


I just want to compare two files,one from windows and the other from
unix. But I do not want to compare them through reading them line by
line. Then I found there is a filecmp module which is used as file and
directory comparisons. However,when I use two same files (one from
unix,one from windows,the content of them is the same) to test its cmp
function, filecmp.cmp told me false.

Later, I found that windows use '\n\r' as new line flag but unix use
'\n', so filecmp.cmp think that they are different,then return false.
So, can anyone tell me that is there any method like IgnoreNewline
which can ignore the difference of new line flag in diffrent
platforms? If not,I think filecmp may be not a good file comparison
module.


Thanks,
higer





More information about the Python-list mailing list