Created
February 14, 2012 09:23
-
-
Save yangjuven/1825162 to your computer and use it in GitHub Desktop.
Get md5 of file without getting all content. It's very pythonic
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
#!/usr/bin/env python | |
import sys, hashlib | |
m = hashlib.md5() | |
with open(sys.argv[1], "rb") as fp: | |
for chunk in iter(lambda :fp.read(128 * m.block_size), ""): | |
m.update(chunk) | |
print m.hexdigest() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
附上参考地址: http://stackoverflow.com/questions/1131220/get-md5-hash-of-a-files-without-open-it-in-python