Applying a decorator to a module

George Sakkis george.sakkis at gmail.com
Thu Nov 27 15:08:29 EST 2008


On Nov 27, 2:54 pm, lkcl <luke.leigh... at googlemail.com> wrote:
> On Nov 27, 7:43 pm, s... at pobox.com wrote:
>
> >     lkcl> Very simple question: how do you apply a decorator to an entire
> >     lkcl> module?
>
> > Function-by-function or class-by-class.  There is no decorator support for
> > modules.
>
> awWww!  i'm going to quietly throw my toys out of my pram.
>
> ... but seriously - doesn't that strike people as... a slightly odd
> omission?

Not really; functions and classes are explicitly defined by "def .."
and "class ...", modules are not.

You can always pass the module to the decorator explicitly:

import mymod
mymod = decorator(mymod)

George



More information about the Python-list mailing list