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

Joseph Andrew Knapka jknapka at earthlink.net
Thu Aug 23 00:27:58 EDT 2001


Donn Cave wrote:
> 
> Quoth Joseph Andrew Knapka <jknapka 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.
> 
> getattr(inst, name)
> 
>         Donn Cave, donn at u.washington.edu

*This* is the answer I wanted. And to think I read
the "built-in functions" docs and completely
overlooked getattr() :-P

Thanks, everyone, for the help!

-- 
# Joe Knapka
# "You know how many remote castles there are along the
#  gorges? You can't MOVE for remote castles!" - Lu Tze re. Uberwald
# Linux MM docs:
http://home.earthlink.net/~jknapka/linux-mm/vmoutline.html



More information about the Python-list mailing list