Intercepting method calls
Diez B. Roggisch
deetsNOSPAM at web.de
Tue Apr 27 14:26:03 EDT 2004
Matt Leslie wrote:
> I took a look at the language reference and it is not immediately clear
> to me how or if I could do this in Python, perhaps I need to override
> the __call__ methods for all the instancemethods in the class? I'm not
> even sure how I could do this... Any help or suggestions appreciated.
A way to accomplish this is the usage of metaclasses. A metaclass gives you
a sort of callback that gets invoked with the classname, the base classes
and the class dictionary before the actual class object is created. Here
you then can creat wrappers around all callables that implement your
desired behaviour.
See this reciepe:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/198078
--
Regards,
Diez B. Roggisch
More information about the Python-list
mailing list