Filesystem and I/O Modules

filecmp

Compares files and directory trees. cmp() can use metadata as a shortcut when shallow=True; use shallow=False to compare contents. dircmp exposes differences between directory entries. Cached comparisons and concurrent changes can affect results.

Formal Syntax & Structure

python syntaxpython
import filecmp

Return Value

module

Module namespace available through import; import is a statement, not a value-returning expression.

Working Example

Example Snippetpython
import filecmpfrom pathlib import Pathfrom tempfile import TemporaryDirectorywith TemporaryDirectory() as folder:    a, b = Path(folder)/"a", Path(folder)/"b"    a.write_bytes(b"tea")    b.write_bytes(b"tea")    print(filecmp.cmp(a, b, shallow=False))
Python Reference