2
我一直在试图向JSON文件写入大量(> 800MB)的数据;我做的试验和错误的一些相当数量得到这个代码:如何编写大型的JSON数据?
def write_to_cube(data):
with open('test.json') as file1:
temp_data = json.load(file1)
temp_data.update(data)
file1.close()
with open('test.json', 'w') as f:
json.dump(temp_data, f)
f.close()
运行它只是调用函数write_to_cube({"some_data" = data})
现在有了这个代码的问题是,它的速度快于数据量小,但是当test.json
文件超过800mb时,问题就来了。当我尝试更新或向其添加数据时,需要很长时间。
我知道有外部库,如simplejson
或,我不确定如何使用它们。
有没有其他办法解决这个问题?
更新:
我不知道怎么这可能是一个重复的,其他文章说什么关于写作或更新一个大的JSON文件,而他们认为,大约只有解析。
Is there a memory efficient and fast way to load big json files in python?
Reading rather large json files in Python
以上都不是解决的这个问题重复。他们没有写任何关于写作或更新的内容。
可能重复的[是 - 这是一个高效的内存和快速的方式来加载大json文件在蟒蛇](http://stackoverflow.com/questions/2400643/is-there-a-memory-efficient-and-fast-way-to-load-big-json-files-in-python) – BPL
基本上JSON并不是格式的好选择,序列化大量的数据。 –
[在Python中读取相当大的json文件]可能的副本(http://stackoverflow.com/questions/10382253/reading-rather-large-json-files-in-python) –