converting string to dict ?

Richard Scott Glazerman gt7781c at prism.gatech.edu
Thu Apr 12 02:08:07 EDT 2001


Jason Cunliffe <jasonic at nomadicsltd.com> wrote:
: A web input form  passes {'name':'Cleopatra'} as a string.

: Please, is there a nice clean function to convert this string to a dict?

: thanks
: - Jason
: ___________________________________________________________
: Jason CUNLIFFE = NOMADICS['Interactive Art and Technology']

what about exec?? (somebody please let me know if there is something wrong
with using exec this way, I've used it many times for just that purpose.)

>>> a = "{'Name':'Cleopatra'}" 
>>> exec 'a = %s' % a
>>> a
{'Name': 'Cleopatra'}

Rich
-- 
Richard Scott Glazerman
Georgia Institute of Technology, Atlanta Georgia, 30332
Email: rich at aepi.atlanta.nu

"This is the time to remember,
 'cause it will not last forever."

	- Billy Joel, "This is the Time"



More information about the Python-list mailing list