How to get back a list object from its string representation?
gagsl-py2 at yahoo.com.ar
Wed Dec 31 19:05:07 CET 2008
En Wed, 31 Dec 2008 04:27:01 -0200, Steven D'Aprano
<steve at remove-this-cybersource.com.au> escribió:
> On Wed, 31 Dec 2008 03:08:29 -0200, Gabriel Genellina wrote:
>> eval is like Pandora´s box, all kind of bad things can come from it. Do
>> not use it with any user-supplied string. If you can restrict the values
>> to be just constants, there is a "safe eval" recipe in
> The ast module in Python 2.6 includes a "literal eval" function:
>>>> ast.literal_eval("[1, 2, 3]")
> [1, 2, 3]
That's a very nice addition!
More information about the Python-list