Appending data to a json file

Michael Torrie torriem at
Mon Apr 3 23:26:41 EDT 2017

On 04/03/2017 08:59 PM, Dave wrote:
> I created a python program that gets data from a user, stores the data 
> as a dictionary in a list of dictionaries.  When the program quits, it 
> saves the data file.  My desire is to append the new data to the 
> existing data file as is done with purely text files.  However, I can't 
> find a way to do that.  The advice I have seen on the web is to load the 
> data when the program starts, append the new user input to the list, 
> then re-write the data file.  Is that the best way, or is there a better 
> way?

If you're talking about a plain text file, can't you just open the file
for append mode and write away to it?

f = open("file","at")
with f:
   f.write("More text.\n")

More information about the Python-list mailing list