【发布时间】:2013-06-19 23:26:05
【问题描述】:
可能的重复:
Finding duplicate files and removing them.
In Python, is there a concise way of comparing whether the contents of two text files are the same?
在 Python 中查看两个文件在内容方面是否相同的最简单方法是什么。
我可以做的一件事是 md5 每个文件并进行比较。有没有更好的办法?
【问题讨论】:
-
我对这个问题的答案很不满意。最佳答案使
filecmp.cmp(a, b)看起来像 逐字节 比较文件,它非常不! 它只是检查缓存的os.stat()签名,它对我来说至少导致误报。只有filecmp.cmp(a, b, shallow=True)进行真正的逐字节比较。 -
@xjcl 我想你的意思是
shallow=False -
@kuzzooroo 是的,该死的!