shelve模块是一个简单的k,v将内存数据通过文件持久化的模块,可以持久化任何pickle可支持的python数据格式
例如:
>>> import shelve >>> a = shelve.open('shelve.text') >>> a['name'] = '王虎' >>> a['info'] = {'name':'王华'} >>> a <shelve.DbfilenameShelf object at 0x00000221229B0F08> >>> a.keys() KeysView(<shelve.DbfilenameShelf object at 0x00000221229B0F08>) >>> list(a.keys()) ['name', 'info'] >>> a['name'] '王虎' >>> a['info'] {'name': '王华'}