Nick Craig-Wood a écrit :
Bruno Desthuilliers <[EMAIL PROTECTED]> wrote:
Can someone suggest an efficient way of calling method whose name is
passed in a variable?
method = getattr(obj, 'method_name', None)
if callable(method):
method(args)
I think that that is needless LBYL...
From experience, it isn't.
getattr(obj, 'method_name')(args)
Will produce some perfectly good exceptions
The problem is that you can't tell (without reading the exception's
message and traceback etc) if the exception happened in you code or
within the called method.
--
http://mail.python.org/mailman/listinfo/python-list