标签:内存 nbsp 数据格式 mic http 持久 UNC 反序列化 image
shelve模块是一个简单的key,value将内存数据通过文件持久化的模块,可以持久化任何picklel可支持的Python数据格式。
序列化源代码:
import shelve
import os
f = shelve.open("shelve_log")
d = {‘1‘:‘a‘,‘2‘:‘b‘}
def test():
return os.system("calc")
f[‘dict‘] = d
f[‘func‘] = test
f.close()
运行后会在当前目录下生成后缀为bak、dat、dir文件。

打开后三份文件都是一样的,内容如下:

反序列化读取:
import shelve
import os
f = shelve.open("shelve_log")
d = {‘1‘:‘a‘,‘2‘:‘b‘} #这行不可少
def test(): #这行不可少
return os.system("calc") #这行不可少
print(f.get(‘dict‘))
f.get(‘func‘)()

标签:内存 nbsp 数据格式 mic http 持久 UNC 反序列化 image
原文地址:https://www.cnblogs.com/endust/p/12311888.html