On this page
filecmp.cmp
Prev: filecmp.clear_cache | Up: filecmp | Next: filecmp.cmpfiles
Rel: filecmp.clear_cache, filecmp.cmpfiles, filecmp.dircmp
Ref: docs.python.org — filecmp.cmp
Tags: #public #python3 #stdlib #filecmp
Import
import filecmp
from filecmp import cmp
Signature & Overview
filecmp.cmp(f1, f2, shallow=True)
Compare two files.
Usage
import filecmp
from pathlib import Path
import tempfile
with tempfile.TemporaryDirectory() as tmp:
a, b = Path(tmp) / "a.txt", Path(tmp) / "b.txt"
a.write_text("same"); b.write_text("same")
assert filecmp.cmp(a, b, shallow=False) is True
Gotchas
- Always pass
shallow=Falsefor content accuracy: Defaultshallow=Trueonly checksos.stat()size/mtime.
REPL Inspect
from filecmp import cmp
help(cmp)
Linked from
Related notes
- tuts/python3/stdlib_module/filecmp/clear_cache Linked here; links to this page; shared tags: #filecmp, #stdlib
- tuts/python3/stdlib_module/filecmp/cmpfiles Linked here; links to this page; shared tags: #filecmp, #stdlib
- tuts/python3/stdlib_module/filecmp/dircmp Linked here; links to this page; shared tags: #filecmp, #stdlib
- tuts/python3/stdlib_module/filecmp Linked here; links to this page; shared tags: #stdlib
- tuts/c/stdlib shared tags: #stdlib
- tuts/c/stdlib/assert shared tags: #stdlib
- tuts/c/stdlib/assert/assert shared tags: #stdlib
- tuts/c/stdlib/assert/static_assert shared tags: #stdlib
- tuts/c/stdlib/ctype shared tags: #stdlib
- tuts/c/stdlib/ctype/isalpha shared tags: #stdlib