I need to save a complex piece of data:
list = ["Animals", {"Cats":4, "Dogs":5}, {"x":[], "y":[]}]
I planned to save several of these lists in a single file, and I also planned to use the pickle module to save this data. I also want to have access to pickled data and add items to lists in the second dictionary. Therefore, after I print the data and edit, the list may look like this:
list = ["Animals", {"Cats":4, "Dogs":5}, {"x"=[1, 2, 3], "y":[]}]
Preferably, I want to save this list (using pickle) in the same file from which I took this piece of data. However, if I simply redistribute the data into the same file (say, I initially saved it in the "File"), in the end I will get two copies of the same list:
a = open("File", "ab") pickle.dump(list, a) a.close()
Is there a way to replace the edited list in a file using a pickle instead of adding a second (updated) copy? Or is there another method I should consider to save this data?
source share