Python (Scripting) - List differences between files using filecmp
by
Jeremy Canfield |
Updated: April 01 2024
| Python (Scripting) articles
The filecmp (File Compare) module can be used to compare files, to determine if the files are the same or if the files contain differences. For example, to compare /tmp/foo.txt to /tmp/bar.txt.
- If the files are the same (no differences) True should be returned.
- If the files contain differences, False should be returned
#!/usr/bin/python3
import filecmp
result = filecmp.cmp("/tmp/foo.txt", "/tmp/bar.txt")
print(f"result = {result}")
Did you find this article helpful?
If so, consider buying me a coffee over at