python文件取MD5

import hashlib

def md5sum(filename, blocksize=65536):
	hash = hashlib.md5()
	with open(filename, "rb") as f:
		#必须是rb形式打开的,否则的两次出来的结果不一致
		for block in iter(lambda: f.read(blocksize), b""):
			hash.update(block)
	return hash.hexdigest()

  

posted @ 2016-04-04 21:05  Rikewang  阅读(1489)  评论(0编辑  收藏  举报