Dictionary to string and back to dictionary??

Derek Basch dbasch at yahoo.com
Fri Aug 23 15:28:20 EDT 2002


Thanks everyone,
I think I will be using pickle because my trusty
'Python 2.1 Bible' doesn't cover eval that well and it
sounds like using pickle would be a little more
reliable.
Cya,
Derek Basch 

--- Mark McEahern <marklists at mceahern.com> wrote:
> > I have a set of records stored as dictionary
> objects.
> > The records must be converted to strings so they
> can
> > be stored in a bsddb (ie...str(record1)). My
> problem
> > is, how do I convert the strings back to a
> > dictionaries after removing the record from the
> bsddb?
> > Any suggestions?
> 
> pickle.
> 
> Or [insert usual caveats about eval here]:
> 
>   $ python
>   Python 2.2.1 (#1, Jun 25 2002, 10:55:46)
>   [GCC 2.95.3-5 (cygwin special)] on cygwin
>   Type "help", "copyright", "credits" or "license"
> for more information.
>   >>> d = {'foo': 1, 'bar': 2}
>   >>> s = repr(d)
>   >>> d2 = eval(s)
>   >>> d2 == d
>   1
> 
> As they say in Wisconsin, and so.
> 
> // m
> -
> 


__________________________________________________
Do You Yahoo!?
Yahoo! Finance - Get real-time stock quotes
http://finance.yahoo.com




More information about the Python-list mailing list