shelve模块
# 将序列化文件操作dump与load进行封装
s_dic = shelve.open("target_file", writeback=True) # 注:writeback允许序列化的可变类型,可以直接修改值
# 序列化::存
s_dic['key1'] = [1, 2, 3, 4, 5]
s_dic['key2'] = {'name': 'Bob', 'age': 18}
s_dic['key1'][2] = 30
s_dic['key2']['age'] = 20
# 反序列化:取
print(s_dic['key1'])
# 文件这样的释放
s_dic.close()