How to create a dictionary from a string?

Michael Spencer mahs at telcopartners.com
Fri Apr 21 20:29:51 EDT 2006


Clodoaldo Pinto wrote:
> Is there a simple way to build a dictionary from a string without using
> eval()?
> 
>>>> s = '{"a":1}'
>>>> d = eval(s)
>>>> d
> {'a': 1}
> 
> Regards, Clodoaldo Pinto
> 

Here is a discussion about one way to do it:
http://tinyurl.com/o8mmm

HTH
Michael




More information about the Python-list mailing list