How to turn a variable name into a string?

stewart.midwinter at gmail.com stewart.midwinter at gmail.com
Fri Mar 11 15:39:30 EST 2005


lots of good answers there, and quickly, too!

I can see that I need to explain a bit further what I'm up to.

I have a number of variables (environmental variables, actually), most
of which will have a value. But some may not have been found by
os.environ.get(), so I set those to None. Now, if any of them are None,
the app cannot proceed, so I want to test for this and warn the user.
I could do something like this (actually, there are more than 3 vars):
a = "c:\\programs"
b = "d:\\data"
c = None  (result of an assignment after the os.environ.get() returned
a KeyError).
if (a is None) or (b is None) or (c is None):
    #do something here
    print 'you are missing some env vars'

But, that seemed clumsy to me, so I wanted to do something more
pythonic, hence my previous post.   So, any suggestions?

thanks!
S




More information about the Python-list mailing list