首页 > 解决方案 > Python比较gz文件的内容

问题描述

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

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

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

标签: pythonfilecomparisonequality

解决方案


你可以使用filecmp图书馆。

import filecmp

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

是文档。


推荐阅读