简体   繁体   English

f.read的Python内存错误

[英]Python memory error with f.read

I have problem with memory in python "Python memory error". 我在python“Python内存错误”中有内存问题。 In fact , I try to recover data from a big .bson file using this script: 实际上,我尝试使用此脚本从大型.bson文件中恢复数据:

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

error message : 错误信息 :

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

thank you for any help you can provide 感谢您提供任何帮助

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

I use this library: https://github.com/bauman/python-bson-streaming 我使用这个库: 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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM