Last active
May 24, 2018 10:20
-
-
Save gsw945/50e5517905067e9f75482416792a3015 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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