execute a function before and after any method of a parent class
Michele Simionato
michele.simionato at gmail.com
Tue Oct 7 09:34:44 EDT 2008
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).
Michele Simionato
More information about the Python-list
mailing list