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) –