TheSaint a écrit :
On 04:08, domenica 15 giugno 2008 [EMAIL PROTECTED] wrote:
what's wrong with getattr(cp, nn) ?
The learning curve to get into these programming ways.
Does gettattr run the snippet passed in?
Nope, it just does what the name implies.
Considering that nn is a name of function, which will be called and (cfl,
value) are the parameters to passed to that function.
Everything in Python's an object (at least anything you can bind to a
name), including functions and methods. Once you have a callable object,
you just have to apply the call operator (parens) to call it. In your
case, that would be:
func = getattr(cc, nn, None)
if callable(func):
result = func(cfl, value)
else:
do_whatever_appropriate_here()
I'll spend some bit on getattr use.
Would be wise IMHO.
--
http://mail.python.org/mailman/listinfo/python-list