Obtaining an member function by name

bonono at gmail.com bonono at gmail.com
Sat Nov 19 09:29:32 EST 2005


f = getattr(obj,"bar")
f()

guy lateur wrote:
> Hi all,
>
> Suppose you have this class:
>
> class foo:
>     def bar():
>
> Suppose you also have the strings "foo" and "bar". How can you obtain the
> function foo.bar()?
> 
> Surely somebody knows..
> 
> TIA,
> g




More information about the Python-list mailing list