Skip to content

Instantly share code, notes, and snippets.

@gsw945
Last active May 24, 2018 10:20
Show Gist options
  • Save gsw945/50e5517905067e9f75482416792a3015 to your computer and use it in GitHub Desktop.
Save gsw945/50e5517905067e9f75482416792a3015 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
import hashlib
def file_md5sum(file_path):
'''计算文件md5值'''
hash_md5 = hashlib.md5()
chunk_size = 4096
with open(file_path, "rb") as f:
chunk = f.read(chunk_size)
while bool(chunk):
hash_md5.update(chunk)
chunk = f.read(chunk_size)
return hash_md5.hexdigest()
if __name__ == '__main__':
file_path = r'C:\Users\Public\Desktop\desktop.ini'
file_md5 = file_md5sum(file_path)
print('file:', file_path)
print('md5:', file_md5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment