How to turn a variable name into a string?

Lonnie Princehouse finite.automaton at
Sat Mar 12 00:11:03 CET 2005

Perhaps try something like this?

variables = ['a', 'b', 'c']

defaults = {
  'a': 'c:\\programs',
  'b': 'd:\\data',
  # etc

  settings = dict([(v, os.environ.get(v, defaults[v])) for v in
except KeyError, k:
  # handle missing variable
  print "you have a problem with %s" % k.args[0]

# Now if you really must have these as independent variables

More information about the Python-list mailing list