使用hashlib模块取文件md5值
#!/usr/bin/python
#encoding:utf-8
import sys, hashlib
def md5sum(f):
md5 = hashlib.md5()
with open(f,‘r‘) as fd:
while True:
data = fd.read(1024*4)
if not data:
break
md5.update(data)
return md5.hexdigest()
if __name__ == "__main__":
print md5sum(sys.argv[1])
[root@geely01 day02]# python md5.py /etc/passwd
387f68820cc1866c0dd350140a4ee641
原文:http://10462974.blog.51cto.com/10452974/1893987