#shelve模块序列化
import shelve,datetime
d=shelve.open('临时文件')
name=['赖xx','赖zz','赖ss']
info={'赖xx':{'年龄':23,'性别':'男'},'赖zz':{'年龄':17,'性别':'女'},'赖ss':{'年龄':12,'性别':'女'}}
d['name']=name
d['info']=info
d['datatime']=datetime.datetime.now()
d.close()
#shelve模块反序列化
import shelve,datetime
d=shelve.open('临时文件')
print(d.get('name'))
print(d.get('info')['赖xx'])
print(d.get('datatime'))
#输出结果
['赖xx', '赖zz', '赖ss']
{'性别': '男', '年龄': 23}
2020-02-21 13:30:47.651910