python实例26[计算MD5]
2015-06-19 14:15
816 查看
代码如下:
hashlib模块帮助:
http://docs.python.org/library/hashlib.html 转载:python实例26[计算MD5]
<span style="font-size:14px;">from hashlib import md5 def calMD5(str): m = md5() m.update(str) return m.hexdigest() def calMD5ForFile(file): m = md5() a_file = open(file, 'rb') m.update(a_file.read()) a_file.close() return m.hexdigest() def calMD5ForFolder(dir,MD5File): import os outfile = open(MD5File,'w') for root, subdirs, files in os.walk(dir): for file in files: filefullpath = os.path.join(root,file) print filefullpath filerelpath = os.path.relpath(filefullpath,dir) md5 = calMD5ForFile(filefullpath) outfile.write(filerelpath + ' ' + md5 + '\n') outfile.close() print calMD5('This is one test string') print calMD5ForFile('c:\\test\\mytest.txt') calMD5ForFolder('c:\\test','c:\\mdfile.md5')</span>
hashlib模块帮助:
http://docs.python.org/library/hashlib.html 转载:python实例26[计算MD5]
相关文章推荐
- python类库26[读写Excel]
- python日志打印重复(诡异)
- python , angular js 学习记录【1】
- sqlite python脚本
- Python学习 之 流程控制
- setuptools 和easy_install介绍和安装方法
- Python学习笔记(3)--- Flask安装
- webdriver+python 对三大浏览器的支持
- Python学习之库引用错误
- python-Levenshtein几个计算字串相似度的函数解析
- Python标准库:内置函数zip(*iterables)
- Python标准库:内置函数zip(*iterables)
- 《Writing Idiomatic Python》前两部分的中文翻译
- python logging
- python的smtplib发邮件
- Python OpenOPC的学习观感
- Python模块 Socket
- Python学习笔记(9):range()与xrange()函数
- Python version 2.7 required, which was not found in the registry
- Python学习笔记(8):input()与raw_input()