save a dictionary in a file

Jeff Shannon jeff at ccvcorp.com
Mon Nov 15 20:09:41 EST 2004


Josiah Carlson wrote:

>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.
>  
>

Ah, my mistake.  (I've never really had call to use shelve *or* pickle, 
and was going off of (apparently erroneous) memories of conversations in 
c.l.py.) 

Still, it does seem that shelve would probably fit the O.P.'s needs...

Jeff Shannon
Technician/Programmer
Credit International




More information about the Python-list mailing list