用Python高效地将字典(哈希)存储到文件的方式?
3 个回答
0
我会用pickle这个工具,看看它的速度是否能满足你的需求。
5
我建议你先试试 shelve 这个模块,看看它的速度是否合适。它正好能满足你的需求。
import shelve
d = shelve.open('filename')
d['name'] = 'path'
d.close()
或者用它来读取数据
d = shelve.open('filename')
d = hash['name']
它其实是对 pickle 的一种封装,提供了一个字典的使用方式。