Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect whether two files are identical in Python [duplicate]

Is making system call to "md5sum file1" and "md5sum file2" and compare two return values enough in this case?

like image 953
jack Avatar asked Nov 17 '09 13:11

jack


People also ask

How can I tell if contents of two files are the same?

Use the diff command to compare text files. It can compare single files or the contents of directories. When the diff command is run on regular files, and when it compares text files in different directories, the diff command tells which lines must be changed in the files so that they match.


1 Answers

If you want to do more than just detect if they differ, or don't trust the hashing solution, there are modules in the standard library called difflib and filecmp that doesn't rely on external programs.

like image 159
Mattias Nilsson Avatar answered Oct 24 '22 21:10

Mattias Nilsson