class callable with any method name

Alex Martelli aleax at aleax.it
Tue Apr 9 17:09:21 EDT 2002


Imer wrote:

> Hi, I'm trying to find a way to implement a class that would allow any
> method name to be called.
> When that happens, a special method would be called and the name of
> the method that was originally called would be passed as an argument.
        ...
> Is there a way to do that ?

Sure: __getattr__ is called for methods as well as attributes.  You
just need to return a callable that wraps/curries whatever you want.


Alex




More information about the Python-list mailing list