call method by name?
Chris Ryland
cpr at emsoftware.com
Thu Jan 24 23:23:32 EST 2002
andreyw at mailandnews.com (andreyw) wrote in message news:<76d5d34e.0201241512.1981f173 at posting.google.com>...
> How to say this in Python?
>
> method_name = 'method1'
> a. at method_name()
The brute force obvious approach (there may be cleaner ways):
>>> class A:
... def m():
... print "m here"
...
>>> mn = "m"
>>> a = A()
>>> a.__class__.__dict__[mn]()
m here
>>>
--
Cheers!
Chris Ryland, Em Software
More information about the Python-list
mailing list