Convert String to Dictionary question

Gustavo Cordova gcordova at hebmex.com
Thu Feb 14 15:49:41 EST 2002


> 
> I saved my dictionary {'hello1': [1, 0, 0]} to a file.
> 
> When I do a readline the I get back a string.
> 
> How do I convert this string to a dictionary?
> 
> Thanks.
> 

You eval() it?

>>> d = { "one":1, "two":2, "three":3 }
>>> print d
{'three': 3, 'two': 2, 'one': 1}
>>> S = str(d)
>>> print S
{'three': 3, 'two': 2, 'one': 1}
>>> dd = eval(S)
>>> print dd
{'one': 1, 'three': 3, 'two': 2}
>>> d is dd
0
>>> 


Do I pass??

:-)

-gustavo




More information about the Python-list mailing list