Data Persistence数据持久层¶
The modules described in this chapter support storing Python data in a persistent form on disk. 本章描述的模块支持以持久形式将Python数据存储在磁盘上。The pickle
and marshal
modules can turn many Python data types into a stream of bytes and then recreate the objects from the bytes. pickle
和marshal
模块可以将许多Python数据类型转换为字节流,然后从字节中重新创建对象。The various DBM-related modules support a family of hash-based file formats that store a mapping of strings to other strings.各种与DBM相关的模块支持一系列基于哈希的文件格式,这些格式存储字符串到其他字符串的映射。
The list of modules described in this chapter is:本章介绍的模块列表如下:
pickle
—Python object serializationPython对象序列化Relationship to other Python modules与其他Python模块的关系Data stream format数据流格式Module Interface模块接口What can be pickled and unpickled?什么可以腌制和不腌制?Pickling Class Instances酸洗类实例Custom Reduction for Types, Functions, and Other Objects类型、函数和其他对象的自定义缩减Out-of-band Buffers带外缓冲器Restricting Globals限制全局变量Performance表演Examples示例
copyreg
—Register注册pickle
support functionspickle
支持函数shelve
—Python object persistencePython对象持久性marshal
—Internal Python object serialization内部Python对象序列化dbm
—Interfaces to Unix “databases”Unix“数据库”接口sqlite3
—DB-API 2.0 interface for SQLite databasesSQLite数据库DB-API 2.0接口Module functions and constants模块函数和常量Connection Objects连接对象Cursor Objects游标对象Row Objects行对象Exceptions例外情况SQLite and Python typesSQLite和Python类型Controlling Transactions控制交易Using高效使用sqlite3
efficientlysqlite3