标签:字符 数据 pen 允许 tar and exp 释放 字典
# 将序列化文件操作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()
标签:字符 数据 pen 允许 tar and exp 释放 字典
原文地址:https://www.cnblogs.com/zhangdajin/p/11141028.html