python模块(shelve)

shelve模块是一个简单的k,v将内存数据通过文件持久化的模块,可以持久化任何pickle可支持的python数据格式

# Author:Sooele


import shelve
import datetime

shelve 转为python
######################
d = shelve.open('shelve_test')  # 打开一个文件
print(d.get("name"))
print(d.get("info"))
print(d.get("date"))

class Test(object):
    def __init__(self, n):
        self.n = n
##########################




shelve 转为其他方式
#######################
# ninfo = {'age':22,"job":'it'}
#
# name = ["alex", "rain", "test"]
# d["name"] = name  # 持久化列表
# d["info"] = info  # 持久化dict
# d["date"] = datetime.datetime.now()  # 持久化列表
#d.close()
############################