md5 加密文件

import hashlib
import os
def get_md5(file_path):
md5 = None
if os.path.isfile(file_path):
f = open(file_path, 'rb')
md5_obj = hashlib.md5()
md5_obj.update(f.read())
hash_code = md5_obj.hexdigest()
f.close()
md5 = str(hash_code).lower()
return md5

if __name__ == "__main__":
file_path = r'D:\\icebox_Train.zip'
md5_1 = get_md5(file_path)
print md5_1

猜你喜欢

转载自www.cnblogs.com/automation-test/p/9578534.html