首页 > 编程语言 > 详细

python:shelve模块

时间:2018-01-02 22:40:52      阅读:209      评论:0      收藏:0      [点我收藏+]
#!usr/bin/env python
# -*- coding:utf-8 -*-

__author__ = "Samson"
import shelve

d = shelve.open(‘shelve_test‘) # 打开一个文件

info = {"age":22,"job":"it"}

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


t = Test(123)
t2 = Test(123334)

name = ["alex", "rain", "test"]
d["name"] = name # 持久化列表
d["info"] = info #持久化dict
d["t1"] = t # 持久化类
d["t2"] = t2

print(d.get("name"))#获取文件中的特定内容
d.close()

python:shelve模块

原文:https://www.cnblogs.com/cansun/p/8179130.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!