getattr problem

Victor Subervi victorsubervi at gmail.com
Tue Dec 1 13:32:41 EST 2009


Hi;
I have the following code that execute without a problem:

import sys,os
sys.path.append(os.getcwd())
import options
storesTables = []
junkStores = string.join(addStore(), ', ')
for table in optionsTables():
  if table not in ('particulars', junkStores):
    storesTables.append(table)
for table in storesTables:
  try:
    fn = getattr(options, table)
    print fn()
  except:
    pass

I need to change the obvious line to this or something similar (that
actually works):

    fn = getattr(options, '%s("names")' % table)

That is, I need to pass the variable "names" to each table as it is called.
How do I do this?
TIA,
Victor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20091201/41b62141/attachment-0001.html>


More information about the Python-list mailing list