python基础-pickle与shelve
2024-08-30 03:05:04
pickle
Example
写入文件
import pickle integers = [1, 2, 3, 4, 5] with open('pickle-example.p', 'wb') as pfile:
pickle.dump(integers, pfile)
读取文件
import pickle with open('pickle-example.p', 'rb') as pfile:
integers = pickle.load(pfile)
print integers
shelve
Example
写入文件
import shelve integers = [1, 2, 3, 4, 5] # If you're using Python 2.7, import contextlib and use
# the line:
# with contextlib.closing(shelve.open('shelf-example', 'c')) as shelf:
with shelve.open('shelf-example', 'c') as shelf:
shelf['ints'] = integers
读取文件
import shelve # If you're using Python 2.7, import contextlib and use
# the line:
# with contextlib.closing(shelve.open('shelf-example', 'r')) as shelf:
with shelve.open('shelf-example', 'r') as shelf:
for key in shelf.keys():
print(repr(key), repr(shelf[key])))
最新文章
- 使用javax.persistence注解配置PO对象
- JAVA多线程编程之生产者消费者模式
- HashMap和Hashtable及HashSet的区别
- Vijos 1061 迎春舞会之三人组舞(DP)
- 消除QQ表情小游戏
- C# Json数据反序列化为Dictionary并根据关键字获取指定值
- Java 编程下使用 Class.forName() 加载类
- Android AES加密算法及事实上现
- 重新想象 Windows 8 Store Apps (19) - 动画: 线性动画, 关键帧动画, 缓动动画
- 为什么C++没有对应realloc的new操作符呢?
- 设计模式 -->; (13)备忘录模式
- SAP MM 无价值物料管理的一种实现思路
- 创建一个MongoDB数据库再到配置成Window服务再设置用户名密码
- [TJOI2009]猜数字
- Oracle的条件in中包含NULL时的处理
- centos系统安装rar解压工具unar
- js运行机制
- Java学习笔记48(DBUtils工具类一)
- Windows 下使用 MinGW 和 CMake 进行开发
- courator - create
热门文章
- Vue 响应式属性
- MFC的运行机理分析+ASC码问题
- POJ 2253 Frogger(最小最大距离)
- Pandoc PDF 中文
- Linux模块机制浅析_转
- eval(function(p,a,c,k,e,d){e=function(c)加解密
- 【转】【selenium+Python WebDriver】之元素定位不到解决办法
- Redis单台的安装部署及集群部署
- C语言的运算符的优先级与结合性+ASCII表
- LeetCode222——Count Complete Tree Nodes