pymd5.py的代码如下:
#-*-coding:utf-8-*-
'''
Created on 2012-5-25
@author: kanpiaoxue
'''
import hashlib
import os
import sys
def printUsage():
print ('Usage: [python] pymd5.py ')
def createMD5(filePath):
if not os.path.isfile(filePath):
printUsage()
else:
tmpLength = 1024
m = hashlib.md5()
with open(filePath, 'rb') as f:
b = f.read(tmpLength)
while b != b'':
m.update(b)
b = f.read(tmpLength)
print filePath, ' MD5:\t', m.hexdigest().upper()
if __name__ == '__main__':
if 2 != len(sys.argv):
printUsage()
else:
f = sys.argv[1]
createMD5(f)
分享到:
2012-05-25 16:45
浏览 1453
评论