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

标签 python hash

在 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/

相关文章:

python - 有没有办法在 Python 中使用 PhantomJS?

java - 如何生成 DomainKeys(不是 DKIM)签名?

hash - 无法加载内核二进制文件 :Invalid SDK hash

jQuery Tabs,如何防止 anchor 跳转

python - 使用 Python 导入 Tweepy 时出错

javascript - 使用 Angular 将请求传递到 DJANGO REST api,然后在 DJANGO View 中返回这些结果

python - 如何获取日期时间序列的随机数的平均值和总和?

c# - 数据结构,C# : ~O(1) lookup with range keys?

ruby - 为什么仅当我从参数中删除 splat 运算符时,Hash#each 方法的这种使用才有效?

python - 在 python 中查找命令失败,出现 "missing argument to -exec"