shlve模块 序列化 python任意的数据
生活随笔
收集整理的这篇文章主要介绍了
shlve模块 序列化 python任意的数据
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
import shelve
d = shelve.open('shelve_test') # 打开一个文件
class Test(object):
def __init__(self, n):
self.n = n
t = Test(123)
t2 = Test(123334)
name = ["alex", "rain", "test"]
d["test"] = name # 持久化列表
d["t1"] = t # 持久化类
d["t2"] = t2
d.close()
## 读取shelve 的值 import shelve
d = shelve.open('shelve_test') # 打开一个文件
val = d.get('test')
print(val)
d.close()
d = shelve.open('shelve_test') # 打开一个文件
class Test(object):
def __init__(self, n):
self.n = n
t = Test(123)
t2 = Test(123334)
name = ["alex", "rain", "test"]
d["test"] = name # 持久化列表
d["t1"] = t # 持久化类
d["t2"] = t2
d.close()
## 读取shelve 的值 import shelve
d = shelve.open('shelve_test') # 打开一个文件
val = d.get('test')
print(val)
d.close()
转载于:https://www.cnblogs.com/dotiger/p/8280322.html
总结
以上是生活随笔为你收集整理的shlve模块 序列化 python任意的数据的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: mongoDB条件操作符
- 下一篇: python中的引用、浅拷贝和深拷贝