Python 比较 gz 文件的内容

Python compare contents of gz files

提问人:Petur Ulev 提问时间:10/10/2020 最后编辑:azroPetur Ulev 更新时间:10/10/2020 访问量:552

问:

我必须比较 Python 中的几对 gz 文件。想法是运行:

f1 = os.popen('file1.gz').read()
f2 = os.popen('file2.gz').read()
print(f1 == f2)

但这似乎很慢,因为应该阅读整个内容。有没有另一种有效的方法可以检查 Python 中 gz 文件的相等性?

Python 文件 比较 相等

评论


答:

2赞 xemeds 10/10/2020 #1

您可以使用该库。filecmp

import filecmp

print(filecmp.cmp('file1.gz', 'file2.gz'))

这是文档。