Python shelve
一、shelve模块时一个简单的k,v将内存数据通过文件持久化的模块,可以持久化任何pickle可支持的python数据的格式.
1 import shelve 2 3 d = shelve.open('shelve_test')#打开一个文件 4 5 class Test(object): 6 def __init__(self,n): 7 self.n = n 8 9 t = Test(123) 10 t2 = Test(12344) 11 12 name = ["wohaoshuai1","wohaoshuai2","wohaoshuai3"] 13 14 d["test"] = name 15 d["t1"] = t 16 d["t2"] = t2 17 18 d.close() 19 20 #解析 21 #a = shelve.open("shelve_test") 22 #a.get("test") 23 #b1 = a.get("t1") 24 #b2 = a.get("t2") 25 #print(b1.n) 26 #print(b2.n)