I have a .data file which I want to update with new data
Here is my python file named pic.py
import pickle
dataset = [['Foam', 'cake', 430], ['other', 'icecream', 50]]
# creating .data file for first time
outfile = open('database.data', 'wb')
pickle.dump(dataset, outfile)
outfile.close()
newdata = ['type','name','price']
with open('database.data','rb') as temp_data:
temp_database = pickle.load(temp_data)
temp_database += newdata
with open('database.data','wb') as temp_data:
pickle.dump(temp_database,temp_data)
now every time when I need to append new data in my .data first I'm loading my .data file using pickle to a temp_database variable and then append my newdata to that variable. After that I have used pickle.dump() method to export my all database that is "temp_database" to database.data file
my problem :>>> "Is there any short method to append new data in .data file using pickle without reading existing data -> append new data -> write and dump new data to existing file? "