1
我是python的新手,我試圖用pickle將幾個python對象存儲到文件中。我知道,同時增加新的對象,以現有的泡菜文件我可以加載現有的對象並連接新一:將python對象(字典)附加到現有的pickle文件
# l is a list of existing dictionaries stored in the file:
l = pickle.load(open('existing_file.p', 'rb'))
new_dict = {'a': 1, 'b':2}
l = l + [new_dict]
# overwriting old file with the new content
pickle.dump(open('existing_file.p', 'rw'), l)
我想檢查是否有附加的物體,像字典到什麼更好的辦法現有的酸洗文件而不覆蓋整個內容。 任何暗示或建議將不勝感激。
非常感謝。它非常完美! –