The filecmp Module

(New in 2.0) The filecmp module, shown in Example 14-4, contains functions to compare files and directories.

Example 14-4. Using the filecmp Module

File: filecmp-example-1.py

import filecmp

if filecmp.cmp("samples/sample.au", "samples/sample.wav"):
    print "files are identical"
else:
    print "files differ!"

# files differ!

In 1.5.2 and earlier, you can use the cmp and dircmp modules instead.

Get Python Standard Library now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.