You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
509 B

1 year ago
import hashlib
def get_file_md5(file_name):
"""
计算文件的md5
:param file_name:
:return:
"""
m = hashlib.md5() # 创建md5对象
with open(file_name,'rb') as fobj:
while True:
data = fobj.read(4096)
if not data:
break
m.update(data) # 更新md5对象
return m.hexdigest() # 返回md5对象
if __name__ == "__main__":
md5_code = get_file_md5("E:\Backup\Tools\SystemISO\kms.txt")
print(md5_code)