Re: Calling class method by name passed in variable

2008-05-23 Thread Sagari
Thanks to everyone for the advice. In fact, since all the called methods trap necessary exceptions, I see no big problems with that. With all respect, Konstantin -- http://mail.python.org/mailman/listinfo/python-list

Re: Calling class method by name passed in variable

2008-05-23 Thread Nick Craig-Wood
Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > 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 calla

Re: Calling class method by name passed in variable

2008-05-23 Thread Bruno Desthuilliers
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... Fro

Re: Calling class method by name passed in variable

2008-05-23 Thread Nick Craig-Wood
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... getattr(obj

Re: Calling class method by name passed in variable

2008-05-23 Thread Bruno Desthuilliers
Sagari a écrit : Greetings, 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) -- http://mail.python.org/mailman/listinfo/python-list

Re: Calling class method by name passed in variable

2008-05-22 Thread Gary Herron
Sagari wrote: Greetings, Can someone suggest an efficient way of calling method whose name is passed in a variable? Given something like: class X: #... def a(self): # ... def b(self): # ... #... x = X() #... v = 'a' How do I call the method of x whose name is stored in v? Use get

Calling class method by name passed in variable

2008-05-22 Thread Sagari
Greetings, Can someone suggest an efficient way of calling method whose name is passed in a variable? Given something like: class X: #... def a(self): # ... def b(self): # ... #... x = X() #... v = 'a' How do I call the method of x whose name is stored in v? PHP code for this would be: