Re: Store multiple dictionaries in a file



Philipp H. Mohr wrote:
> Hello,
>
> I would like to store multiple dictionaries in a file, if possible one per
> line.

Why "one per line" ?

> My code currently produces a new dictionary every iteration and
> passes it on to another peace of code.

May this code rest in piece <grin>

> In order to be able to re-run some
> experiments at a later date I would like to store every dictionary in the
> same file.
> I looked at pickel, but that seems to require a whole file for each
> dictionary.
>
> It would be great if some one could tell me how to do that.

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.

My 2 cents...
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb@xxxxxxxxxxx'.split('@')])"
.



Relevant Pages

  • Re: Writing huge Sets() to disk
    ... pushes it's internal dictionaries ... > Almost anything you do copies references. ... > store the values on disc in a reasonably efficient manner. ... bsddb creaps on me that I can store as a key or value only a string. ...
    (comp.lang.python)
  • Re: Design question.
    ... I need to store a number of dictionaries in certain place. ... by the module dicts? ... then your design is correct. ...
    (comp.lang.python)
  • Re: handling tabular data in python--newbie question
    ... Just jump in python few days. ... I am planning to use the column names as variables to access data, currently I am thinking of using a dictionary to store this file but did not figure out a elegant way to start. ... Let's store the rows in a dictionary of dictionaries, using the first column to index each row. ... rdict = dict(zip(names, cols)) ...
    (comp.lang.python)
  • Re: Store multiple dictionaries in a file
    ... >> I would like to store multiple dictionaries in a file, ... In order to be able to re-run an experiment I want to store ... > A pretty simple solution could be to store all the dicts in another ... > from what you explain I'd say a list) and then pickle this container. ...
    (comp.lang.python)
  • Re: Multikey Dict?
    ... > I could store all of them in a list. ... > that is already in the individual dicts within people. ... > choose one of several unambiguous keys as a key. ... reference use the same object in both dictionaries. ...
    (comp.lang.python)