results not valid after appending one pickle file to another in append binary mode

Viewed 76

I have a main pickle file for my dataset and every few time i also have a new pickle file for some new data so i want to append the newly generated pickle file to the main pickle file. The results are not accurate if i use append this way

with open('new_pickle', 'rb') as f:
               encoded = pickle.load(f)
with open("encodings.pickle",'ab+') as outfile:
               pickle.dump(encoded,outfile)

What I tried but not satisfied because the write mode is not what i want . I need to do this via append mode so that the new results should add to the main pickle i.e encodings.pickle:

with open("encodings.pickle", 'rb') as fa:
               encoded1 = pickle.load(fa)
with open('encodings_backup.pickle', 'wb') as fa:
               pickle.dump(encoded1,fa)
with open('new_pickle', 'rb') as f:
               encoded = pickle.load(f)
encoded1.update(encoded)

with open("encodings.pickle",'wb') as outfile:
           pickle.dump(encoded1,outfile)
0 Answers
Related