|
本帖最后由 ant586 于 2015-7-25 18:29 编辑
# _*_ coding:utf-8 _*_
import hashlib
import time
def md5_for_file1(one_file):
md5 = hashlib.md5()
fp = open(one_file, 'rb')
while True:
chunk = fp.read(8192)
if not chunk:
break
md5.update(chunk)
fp.close()
print md5.hexdigest()
t = time.time()
md5_for_file1('aa.pdf')
print time.time() - t
代码如上,还有优化的空间吗,代码功能是根据文件内容计算出文件MD5值,
现在要考虑大文件,比如上100M的文件
|
|