python中md5和字符串相关操作

来源:互联网 发布:光纤宽带软件 编辑:程序博客网 时间:2024/05/29 06:26
string[from : to]
text = 'I love Python.'
text[0:1] ## I
text[:1]  ## I
text[2:6] ## love
text[7:]  ## Python.

#字符串md5,用你的字符串代替’字符串’中的内容。import hashlib
md5=hashlib.md5(‘字符串’.encode(‘utf-8′)).hexdigest()
print(md5)#求文件md5
import hashlib
#文件位置中的路径,请用双反斜杠,如’D:\\abc\\www\\b.msi’
file=’[文件位置]‘
md5file=open(file,’rb’)
md5=hashlib.md5(md5file.read()).hexdigest()
md5file.close()
print(md5)
0 0