getattr problem

Victor Subervi victorsubervi at gmail.com
Tue Dec 1 14:32:02 EST 2009


On Tue, Dec 1, 2009 at 3:17 PM, Jean-Michel Pichavant <
jeanmichel at sequans.com> wrote:

> Victor Subervi wrote:
>
>> 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
>>
> I'm not sure I understood what your are trying to do.
>
>
>  try:
>   fn = getattr(options, table)
>   fn(names)
>  except:
>   pass
>

Thank you.
V
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20091201/bba2f151/attachment-0001.html>


More information about the Python-list mailing list