How to turn a variable name into a string?

Stewart Midwinter stewart.midwinter at gmail.com
Fri Mar 11 13:50:37 EST 2005


I'd like to do something like the following:

a = 1; b = 2; c = None
mylist = [a, b, c]
for my in mylist:
    if my is None:
    print 'you have a problem with %s' % my         #this line is problematic

>>> You have a problem with None

What I want to see in the output is:
>>> You have a problem with c

How do I convert a variable name into a string?

thanks!

-- 
Stewart Midwinter
stewart at midwinter.ca
stewart.midwinter at gmail.com



More information about the Python-list mailing list