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
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:
> For your other examples there are gross hacks using the dictionaries
> that represent the local and global symbol tables, so we translate
> your examples fairly directly, but stylistically we'd usually stay
> away from that kind of thing.
Thanks to everyone for all the comments. I am migrating f
Quite forgot to add the obvious example (in PHP):
$a = 'b';
$obj =& new $a(); // instantiating class b()
--
http://mail.python.org/mailman/listinfo/python-list
Greetings,
Sorry for a newbiw question: what is a most elegant and/or effective
way to reference vars, methods and classes by their names in Python?
To illustrate, PHP code:
$a = ''b';
$$a = $something; // assign to $b
$$a($p1); // call function b($p1)
$obj->$a(); // call method b() of the insta