call method by name?
Mark McEahern
marklists at mceahern.com
Thu Jan 24 18:55:18 EST 2002
Chris Liechti wrote:
> apply(a, method_name)
That won't work:
$ python
Python 2.2 (#1, Dec 31 2001, 15:21:18)
[GCC 2.95.3-5 (cygwin special)] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> class foo:
... def bar(self):
... print "bar"
...
>>> f = foo()
>>> f.bar()
bar
>>> apply(f, "bar")
Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: foo instance has no __call__ method
>>>
// mark
More information about the Python-list
mailing list