【发布时间】:2010-08-02 18:07:06
【问题描述】:
我有一个 python 应用程序,我在其中创建要在 windows 中使用的包,然后在 linux python 应用程序中进行比较。我正在为 windows 中的文件创建一个 md5,以便稍后在 linux 中检查。问题是同一文件上的相同代码在每个环境中给出不同的 Md5 哈希结果。下面是我用来计算 Md5 的方法。 (每一端都是相同的代码,我在 windows/linux 环境中都使用 Python 2.6.5)当我在不同环境中的同一个文件上运行它时,我得到不匹配的 md5 哈希。
def md5_for_file(filePath):
md5 = hashlib.md5()
file = open(filePath)
while True:
data = file.read(8192)
if not data:
break
md5.update(data)
file.close()
return md5.hexdigest()
感谢任何想法或建议。
【问题讨论】:
标签: python