python implementaion md5sum function

#!/usr/bin/env python
#encoding=utf-8
import hashlib,md5
print md5.new(file("/home/mlzboy/pycurl/examples/left_dat/doc_001.dat").read()).hexdigest()
f=open("/home/mlzboy/pycurl/examples/left_dat/doc_001.dat","rb").read()
#f=f.decode("gb18030","ignore")
#print f.encode("utf-8")
m=hashlib.md5()
m.update(f)
#print m.digest()
print m.hexdigest()

the result is the same as md5sum utility

原文地址:https://www.cnblogs.com/lexus/p/2437741.html