我在 python“Python 内存错误”中遇到内存问题。事实上,我尝试.bson
使用这个脚本从一个大文件中恢复数据:
with open('xxxx.bson','rb') as f:
data = bson.decode_all(f.read())
错误信息 :
data = bson.decode_all(f.read())
MemoryError
感谢您提供任何帮助
我在 python“Python 内存错误”中遇到内存问题。事实上,我尝试.bson
使用这个脚本从一个大文件中恢复数据:
with open('xxxx.bson','rb') as f:
data = bson.decode_all(f.read())
错误信息 :
data = bson.decode_all(f.read())
MemoryError
感谢您提供任何帮助
您可以通过切换到 来减少内存消耗decode_file_iter
,其中 1) 需要一个文件(而不是其内容)作为输入,以及 2) 返回一个生成器。
我使用这个库: 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()