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

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Tue Oct 7 23:44:10 CEST 2008

En Tue, 07 Oct 2008 10:34:44 -0300, Michele Simionato  
<michele.simionato at gmail.com> escribió:

> On Oct 3, 9:23 pm, "Gabriel Genellina" <gagsl-... at yahoo.com.ar> wrote:
>> Ok, but then you have to explicitely decorate every method. To avoid  
>> this,  
>> you may use a metaclass; this article by Michael Foord explains  
>> how:http://www.voidspace.org.uk/python/articles/metaclasses.shtml#a-metho...
> Since Python 2.6 is out, I would recommend using a class decorator for
> this task.
> The class decorator is not inherited, so in order to decorate methods
> in subclasses
> one has to repeat it, which I see as a feature (explicit is better
> than implicit).
> Otherwise the readers of your classes will not have any visual clue
> that something
> magic is going on; moreover, you will lower the risk of decorating
> methods
> that should not be decorated (I mean, in case of accidents).

Good to know, I was not aware of the difference.

Gabriel Genellina

More information about the Python-list mailing list