save a dictionary in a file
jcarlson at uci.edu
Mon Nov 15 23:33:55 CET 2004
Jeff Shannon <jeff at ccvcorp.com> wrote:
> Luis P. Mendes wrote:
> > my program builds a dictionary that I would like to save in a file.
> As others have said, there should be no reason to convert to a list
> before pickling -- AFAIK, there's no ban against pickling dictionaries.
> You might also look into the Shelve module, which implements a
> filesystem-persisting object with dictionary access syntax. (And which,
> IIRC, uses pickled dictionaries under the covers.)
It doesn't. It uses a bsddb database.
A bsddb (really anydbm which can give you bsddb) database is merely a
string key->string value mapping (for btree and hash mappings). You
access it via string keys, and its values are automatically translated
to/from strings via Pickle. The only way you actually pickle and
unpickle dictionaries is by having a dictionary in a value.
More information about the Python-list