[Python-ideas] Syntax for defining parametric decorators
Greg Ewing
greg.ewing at canterbury.ac.nz
Mon Jul 9 00:24:58 CEST 2012
Mike Graham wrote:
> def timesn(n)(f):
> def inner(y):
> return n * f(y)
> return inner
+1 from me on this. Scheme has an analogous feature, btw, which is
very elegant. I'd love to see this in Python.
As has been pointed out, you can go further and collapse this
into
def timesn(n)(f)(y):
return n * f(y)
This means it would also be useful for non-parametric decorators
as well, e.g.
def fivetimes(f)(x):
return 5 * f(x)
--
Greg
More information about the Python-ideas
mailing list