Issue 6306: filecmp.cmp can not compare two files from different OS with the same content (original) (raw)

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.

I think maybe it's a bug. If filecmp.cmp can support two platform files with the same content and only the diffrent last newline flag, that's would be wonderful.

If you do not want to compare them by reading line by line, then you are doing a binary comparison (which is what filecmp does) and the two files are, indeed, different. If you want to compare them in text mode, you are moving into 'diff' territory and could use difflib instead.

If you nevertheless want to propose an additional text-and-universal-newline-mode version of cmp (it would be best if you were prepared to write the patch), please bring it up on python-ideas for community discussion, as it is not clear that it is a good idea. If you get a consensus that it is a good idea you can reopen this ticket with a pointer to the discussion.