execute a function before and after any method of a parent class

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sat Oct 4 05:47:38 CEST 2008


On Fri, 03 Oct 2008 16:03:22 +0200, TP wrote:

> Hi everybody,
> 
> I would like to be able to specialize an existing class A, so as to
> obtain a class B(A), with all methods of B being the methods of A
> preceded by a special method of B called _before_any_method_of_A( self
> ), and followed by a special method of B called _after_any_method_of_A(
> self ).
> 
> The goal is to avoid to redefine explicitly in B all methods of A.
> 
> Is this possible in Python?

You may be able to adapt this code to do what you are after:


http://code.activestate.com/recipes/91192/



-- 
Steven



More information about the Python-list mailing list