Store multiple dictionaries in a file

Philipp H. Mohr phm4 at kent.ac.uk
Thu Jun 30 07:30:06 EDT 2005


Thank you for you answer.

> > I would like to store multiple dictionaries in a file, if possible one per
> > line.
>
> Why "one per line" ?

I agree with you that it sounds like nasty code :-) but there is a good
reason for doing it this way - I think. My code collects data (attributes)
of its current environment, e.g. date, time, location, etc.
These values are put into a dictionary and passed to another program which
processes the data. The dictionary (or vector of attributes) is the only
interface between both progs. The one which creates the dictionary can
forget about it after it has passed it on. This is where the storing comes
into action. In order to be able to re-run an experiment I want to store
the dictionaries in a file. Also the program might not run continuasly,
therefore if I write all of them to a file, on after the other, I would be
able to re-run the experiment much easier.

Hope this makes sense.

Thank you,
Phil

>
> A pretty simple solution could be to store all the dicts in another
> container (list or dict, depending on how you need to retrieve'em, but
> from what you explain I'd say a list) and then pickle this container.



More information about the Python-list mailing list