Dictionary from String?

gslindstrom at gmail.com gslindstrom at gmail.com
Sun May 8 15:39:53 EDT 2011


On May 8, 2011 2:00pm, Dan Stromberg <drsalists at gmail.com> wrote:

> On Sun, May 8, 2011 at 8:20 AM, Greg Lindstrom gslindstrom at gmail.com>  
> wrote:

> Is it possible to create a dictionary from a string value? Something  
> along these lines (but that works):

> >>> mystring = "{'name':'greg','hatsize':'7 5/8'}"
> >>> mystring


> "{'name':'greg','hatsize':'7 5/8'}"
> >>> dict(mystring)
> Traceback (most recent call last):
> File "", line 1, in
> ValueError: dictionary update sequence element #0 has length 1; 2 is  
> required


Yes. It works like a champ. Thanks!
--greg
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110508/6896e9de/attachment-0001.html>


More information about the Python-list mailing list