Probably a stupid question... name-->method lookup

Andrew Dalke dalke at dalkescientific.com
Wed Aug 22 11:19:42 EDT 2001


Joseph Andrew Knapka:
>I have a method name (string) and a class object. I'd like to
>be able to look up the the named unbound method of the class.

>>> class Spam:
...  def eggs(self):
...   return 1
...
>>> umeth = getattr(Spam, "eggs")
>>> spam = Spam()
>>> umeth(spam)
1
>>>

                    Andrew






More information about the Python-list mailing list