[Python-ideas] setting function properties with a decorator syntax

Greg Ewing greg.ewing at canterbury.ac.nz
Fri Mar 19 02:50:56 CET 2010

spir wrote:

> def powerN(n):
>     def f(x,n=n):	# ugly ;-)
>         return x ** n
>     return f

Since nothing can change the value of n there after powerN
returns, there's no need for default argument abuse. You
can just write

   def powerN(n):
      def f(x):
        return x ** n
      return f


More information about the Python-ideas mailing list