Interesting decorator use.

Steven Bethard steven.bethard at gmail.com
Thu Feb 24 17:20:30 EST 2005


Tom Willis wrote:
>>> Question on decorators in general. Can you parameterize those?
>
> Wow thanks for the explanation!! Some of it is a bit mind bending to
> me at the moment , but I'm going to mess with it a bit.

Oh, I also should have mentioned that there's some explanation at:

http://www.python.org/peps/pep-0318.html

Specifically on parameterizing:

"""The current syntax also allows decorator declarations to call a 
function that returns a decorator:

@decomaker(argA, argB, ...)
def func(arg1, arg2, ...):
     pass

This is equivalent to:

func = decomaker(argA, argB, ...)(func)

The rationale for having a function that returns a decorator is that the 
part after the @ sign can be considered to be an expression (though 
syntactically restricted to just a function), and whatever that 
expression returns is called. See declaration arguments [15]."""

But playing around with it is, IMHO, definitely the best way to figure 
it out. =)

STeVe



More information about the Python-list mailing list