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)
我想检查是否有附加的物体,像字典到什么更好的办法现有的酸洗文件而不覆盖整个内容。 任何暗示或建议将不胜感激。
非常感谢。它非常完美! –