[Python-ideas] Before and after the colon in funciton defs.

Ron Adam ron3200 at gmail.com
Fri Sep 23 17:40:12 CEST 2011

On Fri, 2011-09-23 at 11:11 +1000, Nick Coghlan wrote:
> 4. Function scoped variables
> This is the approach most analogous to C's static variables - named
> variables that are shared across all invocations of a function, rather
> than being local to the current invocation. In essence, each function
> becomes its own closure - just as a function can share state across
> invocations by using an outer function for storage, this technique
> would allow a function to use its *own* cell array for such storage.
> Framing the idea that way also suggests a fairly obvious spelling:
>     def f(x):
>         nonlocal i=i # Use 'f' as a closure over *itself*
>         return x + i
> With this spelling, the above would be roughly equivalent to:
>     def outer():
>         i = i
>         def f(x):
>             return x + i
>         return f
>     f = outer()
> The only visible difference would be that the cell referenced by 'i'
> would be stored directly on 'f' rather than on an outer function. 


I think this will work just fine.

Will the same change be made to global?


More information about the Python-ideas mailing list