[Python-Dev] closure semantics

Guido van Rossum guido at python.org
Tue Oct 21 19:09:28 EDT 2003


> Why not make local variables attributes of the function, i.e.
> replace:
> 
>     def inner():
>        global x in outer
>        x = 42
> 
> with:
> 
>     def inner():
>        outer.x = 42

Because this already means something!  outer.x refers to the attribute
x of function outer.  That's quite different than local variable x of
the most recent invocation of outer on the current thread's call stack!

> Global variables could then be assigned via:
>     global.x = 42

This has a tiny bit of appeal, but not enough to bother.

--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-Dev mailing list