Python shelve 模块
实例
演示类似书架词典的界面:
import shelve
# Shelve provides a dictionary-like persistent storage
data = {'name': 'Emil', 'age': 25}
print(f"Data to store: {data}")
print('Use shelve.open() to persist this data to disk')
亲自试一试 »
定义和用法
shlve 模块提供了一个简单的持久化字典对象,用于存储 Python 对象。
使用它可以通过类似字典的接口(由数据库支持)将 Python 对象保存到磁盘或从磁盘检索 Python 对象。
成员
| 成员 | 描述 |
|---|---|
| DbfilenameShelf | 使用特定数据库文件名的 Shelf 实现。 |
| Shelf | Shelf 实现的基类。 |
| open() | 打开持久化字典以进行读写操作。 |

