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

AB antonio.a.barbosa at gmail.com
Thu Aug 18 18:05:24 EDT 2011


Hi,

If the «variables» are named attributes you can use getattr.


#----------------
class colors:
	red=1
	green=2
	blue=3
	
c=colors()

a=['red','green','blue']

for v in a:
	print v,getattr(c,v)
#-----------

AB



More information about the Python-list mailing list