在文件中存储大型python字典的最佳方法 [英] Best way to store a large python dictionary in a file

查看:74
本文介绍了在文件中存储大型python字典的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 python 脚本(脚本 1),它生成一个大的 python 字典.该词典必须由另一个脚本(脚本 2)读取.任何人都可以建议我编写由脚本 1 生成的 Python 字典并由脚本 2 读取的最佳方法.过去我曾使用 cPickle 编写和阅读如此大的字典.有没有更好的方法来做到这一点?

I have a python script (script 1) which generate a large python dictionary. This dictionary has to be read by an another script (script 2). Could any one suggest me the best way to write the python dictionary generated by script 1 and to be read by script 2. In past I have used cPickle to write and read such large dictionaries. Is there a beter way to do this?

推荐答案

shelve 将让您分别访问每个项目,而不是要求您每次都序列化和反序列化整个字典.

shelve will give you access to each item separately, instead of requiring you to serialize and deserialize the entire dictionary each time.

这篇关于在文件中存储大型python字典的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆