Appending data to a json file
python at mrabarnett.plus.com
Tue Apr 4 16:51:58 EDT 2017
On 2017-04-04 21:00, Dennis Lee Bieber wrote:
> On Tue, 4 Apr 2017 13:23:52 -0400, Dave <dboland9 at fastmail.fm> declaimed
> the following:
>>I don't care for the idea of replacing the data file for every save. My
>>preference would to append to the existing data file - makes more sense.
>>However, that is not how json works. So, I'm considering other
>>alternatives for a data file structure. Paired data (key and value) is
>>not really required, but my feeling is that it makes the data file more
>>robust. A database seems a little over the top for this situation since
>>there is no querying of data - just load and save.
> Somebody must eventually have to retrieve stuff from this file for some
> use; otherwise it is nothing but an ever-expanding waste of disk space.
> A database, at the very least, means you never have to read the old
> contents before adding new data. However, lacking any indication of /what/
> the data contains ("dictionary of dictionaries" only indicates a nested
> structure at the top level -- but does not indicate if it is possible for
> an "append" pass to overwrite a pre-existing subdictionary should the outer
> dictionary key be a duplicate).
> Possibly a CSV format would suffice...
Would the 'shelve' module module suffice? (OK, it's not plain text, but
neither is a DB.)
More information about the Python-list