Comparing files in Python


Python tip:

You can check if two files are equal with cmp from the filecmp module. It returns True if the files are equal and False if they're not.

For example:

import filecmp

print(filecmp.cmp("file.pdf", "file.pdf"))
# => True

print(filecmp.cmp("file.pdf", "file1.pdf"))
# => False