[Tutor] Re: Persistent Dictionary Variable
Andrei
project5@redrival.net
Fri Jun 27 13:52:05 2003
Jacob Abraham wrote:
<snip>
>>>>a={'key1':[1,2,3],'key2':'value'}
>>>>b=str(a)
>>>>b
>
> "{'key1':[1,2,3],'key2':'value'}"
>
>>>># b is right now a string how do I convert it back
>
> ...into a dictionary variable
>
You could add at the end of that code:
b = eval(b)
Note that when using eval, you must be confident the source of the
string you're going to eval is trustworthy, otherwise Bad Things might
happen since you're executing code you might not have written yourself.
Andrei
=====
Mail address in header catches spam. Real contact info (decode with rot13):
cebwrpg5@bcrenznvy.pbz. Fcnz-serr! Cyrnfr qb abg hfr va choyvp cbfgf. V
ernq gur yvfg, fb gurer'f ab arrq gb PP.