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

Emile van Sebille emile at fenx.com
Wed Aug 22 17:21:34 EDT 2001


Does this help get you started?


>>> class A:
...     def a(self):
...             print 'A.a()'
...
>>> class B(A):
...     pass
...
>>> eval('B.%s' % 'a')
<unbound method A.a>

--

Emile van Sebille
emile at fenx.com

---------
"Joseph Andrew Knapka" <jknapka at earthlink.net> wrote in message
news:3B83C8DD.37316862 at earthlink.net...
> 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.
> I know that TheClass.__dict__[<methodname>] will kinda
> work, but it will fail if <methodname> is implemented only in
> a base class of TheClass. I could do the Python method lookup
> dance via __bases__ etc., but I'd be surprised if there weren't
> already a standard function to do it. Sadly, perusal of the
> tutorial, library reference, language reference (briefly),
> and FAQ has thus far been unenlightening. Pointers
> appreciated.
>
> Thanks in advance,
>
> --
> # Joe Knapka
> # Member, GFAPOOA (Global Front Against Promulgation Of Obscurantist
> Acronyms)
> # Linux MM docs:
> http://home.earthlink.net/~jknapka/linux-mm/vmoutline.html




More information about the Python-list mailing list