how to repeat function definitions less

Michele Simionato michele.simionato at gmail.com
Sun Mar 15 08:19:24 CET 2009


On Sun, Mar 15, 2009 at 7:33 AM, alex goretoy
<aleksandr.goretoy at gmail.com> wrote:
> sweet, I've been wondering how those work. I've read some stuff about them
> and still doesn't make sense to me. Why would I want to use it....Please
> explain, thank you

Well, the typical usage for class decorators is to dynamically add
methods to a class, as you
have just seen. I also suggest you to look at this recipe by Raymond
Hettinger, about adding
comparison methods: http://code.activestate.com/recipes/576685/
Another typical use case is to register classes. You can also use
class decorators to modify
class (for instance, think of a "debug" class decorator replacing
methods with a debug-friendly
version of them).

                   Michele Simionato



More information about the Python-list mailing list