gpt4 book ai didi

python - 在 python 中,从文件的最后 4KB 创建 md5 哈希

转载 作者:太空宇宙 更新时间:2023-11-03 12:41:52 24 4
gpt4 key购买 nike

在 python 中,给定一个非常大的文件 (~700MB),我如何仅从该文件的最后 4096kb 创建 md5 哈希?

最佳答案

您可以使用 seek将文件指针移动到文件末尾,hashlib对于 MD5:

import hashlib
with open('really-large-file', 'rb') as f:
f.seek(- 4096 * 1024, 2)
print (hashlib.md5(f.read()).hexdigest())

关于python - 在 python 中,从文件的最后 4KB 创建 md5 哈希,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8631688/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com