hash
什么是hash?
hash是一种算法,该算法接受传入的内容,经过运算得到一串hash值
为何用hash?
hash值有三大特性:
1.只要传入的内容一样,得到的hash值必然一样
2.只要使用的hash算法固定,无论传入的内容多大,得到的hash值的长度是固定的
3.不可以用hash值逆推出来的内容
基于1.2可以用于下载文件时做一致性校验等
基于2.3可以用于密码的加密等
如何使用hash
import hashlib
m = hashlib.md5() # 相当于造工厂
m.update(‘hello’.encode(‘utf-8’)) # 相当于送原料
m.hexdigest() # 相当于产出产品
shelve
import shelve # 序列化,将内容以字典的形式存入文件
f=shelve.open(r'sheve.txt')
# f['stu1_info']={'name':'egon','age':18,'hobby':['piao','smoking','drinking']}
# f['stu2_info']={'name':'gangdan','age':53}
# f['school_info']={'website':'http://www.pypy.org','city':'beijing'}
print(f['stu1_info']['hobby'])
f.close()
xml
<?xml version="1.0"?> <data> <country name="Liechtenstein"> <rank updated="yes">2</rank> <year>2008</year> <gdppc>141100</gdppc> <neighbor name="Austria" direction="E"/> <neighbor name="Switzerland" direction="W"/> </country> <country name="Singapore"> <rank updated="yes">5</rank> <year>2011</year> <gdppc>59900</gdppc> <neighbor name="Malaysia" direction="N"/> </country> <country name="Panama"> <rank updated="yes">69</rank> <year>2011</year> <gdppc>13600</gdppc> <neighbor name="Costa Rica" direction="W"/> <neighbor name="Colombia" direction="E"/> </country> </data>