Thoughts on object representation in a dictionary

Paul Rubin http
Sat Dec 10 12:21:32 EST 2005


"py" <codecraig at gmail.com> writes:
> Well the other thing is that I am allowed to store strings in this
> dictionary...so I can't just store the Engine and Body object and later
> use them.  ....this is just a requirement (which i dont understand
> either)...but its what I have to do.

Probably so that the object store can later be moved offline, with the
shelve module or DB API or something like that.

> So my question is there a good way of storing this information in a
> nested dictionary such that if I receive this dictionary I could easily
> pull it apart and create Engine and Body objects with the information?
> Any suggestions at all?  keep in mind I am limited to using a
> dictionary of strings...thats it.

The spirit of the thing would be serialize the objects, maybe with
cPickle, as Steven suggests.  A kludgy way to thwart the policy
might be to store the objects in a list instead of a dictionary:
x[0], x[1], etc.  Then have a dictionary mapping keys to subscripts
in the list.  The subscripts would be stringified ints: '0','1',... .



More information about the Python-list mailing list