How to convert a list of strings into a list of variables

Chris Angelico rosuav at gmail.com
Thu Aug 18 19:48:56 CEST 2011


On Thu, Aug 18, 2011 at 5:09 PM, John Gordon <gordon at panix.com> wrote:
> for x in list_of_strings:
>    list_of_variables.append(eval(x))
>

If this really is what you need, you can simplify it by using the
globals() dictionary - it's a regular dictionary whose contents are
all the global variables in your current module. Inside a function,
use locals() instead.

http://docs.python.org/library/functions.html#globals

ChrisA



More information about the Python-list mailing list