Safe eval, or how to get list from string

bwooster47 at gmail.com bwooster47 at gmail.com
Fri May 13 11:55:26 EDT 2005


I've to use ConfigParser.

It returns values that are exactly in the config file, so get string
variables like:
int1 with quotes and characers: "42"
this is easy to convert to int:
realint = int(int1)

I've read the tutorial, and the FAQ, and not sure if I missed it, but
other than calling eval (which everyone says is unsafe), I don't know
if there is another way to do this:
string1 has "this is a string" or however complex a string (""" aaa
""").
I can do
realstring = eval(string1)
or
if there is list1 = "[ 'filea', 'fileb', ]", I can get at list by
doing:
reallist = eval(list1)

is there an easier/simpler method of doing the same thing as realstring
and reallist lines above?




More information about the Python-list mailing list