python 学习第四十七天shelve模块

    shelve模块是一个简单的k,v将内存数据通过文件持久化的模块,可以持久化任何pickle可支持的python数据格式。

1,序列化

  import shelve

f=shelve.open('shelve_test')

names=['www.96net.com.cn',"www.dc3688.com","www.baidu.com"]

info=['name','woodson','age':22]

f["names"]=names

f['info_other']=info

f.close()

2,反序列化

import shelve

d=shelve.open('shelve_test')

print(d['name'])

删除 d['info_other']

就是将序列持久存在一个文件中。

猜你喜欢

转载自www.cnblogs.com/96net/p/9769196.html