def md5sum(filename, size=4096):
md5 = hashlib.md5()
with open(filename, 'rb') as f:
while True:
b = f.read(size)
if not b:
break
md5.update(b)
return md5.hexdigest()
if name == ‘main‘:
import sys
if len(sys.argv) < 2:
print 'usage: %s <infile>' % sys.argv[0]
exit()
infile = sys.argv[1]
md5_value = md5sum(infile)
print '{} {}'.format(md5_value, infile)
```
运行结果