python学习笔记-Day6(1)
2016-02-28 11:46
676 查看
shelve模块是一个简单的k,v将内存数据通过文件持久化的模块,可以持久化任何pickle可支持的python数据格式
>>> s=shelve.open('test') >>> name=['a','b'] >>> name = ['a','b'] >>> s['t'] =name >>> s.get('t') ['a', 'b'] >>> >>> n = s.get('t') >>> n[0] 'a'
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()
相关文章推荐
- python_Python中用format函数格式化字符串的用法
- Python 判断一个字符串是否是数字
- python之路(十一)-socke开发
- python之路(十一)-类相关
- Python Tab自动补全
- NumPy 简单应用
- python学习笔记(六)文件夹遍历,异常处理
- python日记——使用django心得
- leetcode第21题——*Merge Two Sorted Lists
- Python基础0228
- 第二天 Python3.4.2 函数
- Python基础语法(Python基础知识点)
- python开发学习-day07(面向对象之多态、类的方法、反射、新式类and旧式类、socket编程)
- 六、keytool工具
- Python基础语法(Python基础知识点)
- python 写的一个爬虫程序源码
- Python中time模块和datetime模块的用法示例
- 简要讲解Python编程中线程的创建与锁的使用
- python3 装饰器
- 第二天 Python3.4.2 字符串的格式化 和 常用操作