Need to call functions/class_methods etc using string ref :How

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Mon Nov 26 15:42:34 EST 2007


Donn Ingle a écrit :
>>target = <module or any other objet here>
>>for funcname in funclist:
>>func = getattr(target, funcname, None)
>>if callable(func):
>>func(*args, **kwargs)
> 
> Nice. 'callable' is new to me.

What about getattr, then ?-)

And FWIW, callable will disappear in py3k... (anyway, you can just test 
if the object has a __call__ method).



More information about the Python-list mailing list