import hashlib
def calc_md5(filename):
md5_hash = hashlib.md5()
with open(filename, "rb") as f:
# Read and update hash in chunks of 4K
for byte_block in iter(lambda: f.read(4096), b""):
md5_hash.update(byte_block)
print(md5_hash.hexdigest())
标签:hashlib,hash,Python,update,生成,MD5,byte,filename,md5
From: https://blog.51cto.com/u_13893439/9113866