3

我在 python“Python 内存错误”中遇到内存问题。事实上,我尝试.bson使用这个脚本从一个大文件中恢复数据:

with open('xxxx.bson','rb') as f:
    data = bson.decode_all(f.read())

错误信息 :

data = bson.decode_all(f.read())
MemoryError

感谢您提供任何帮助

4

2 回答 2

1

您可以通过切换到 来减少内存消耗decode_file_iter,其中 1) 需要一个文件(而不是其内容)作为输入,以及 2) 返回一个生成器。

于 2016-03-23T13:32:16.453 回答
0

我使用这个库: https ://github.com/bauman/python-bson-streaming

from bsonstream import KeyValueBSONInput
f = open("xxxx.bson", 'rb')
stream = KeyValueBSONInput(fh=f)
for dict_data in stream:
    print dict_data
f.close()
于 2016-03-23T19:16:05.337 回答