[Python-Dev] closure semantics (original) (raw)

Walter Dörwald walter at livinglogic.de
Tue Oct 21 19:06:30 EDT 2003


Guido van Rossum wrote:

[...] Maybe "global x in f" would work?

def outer(): x = 1 def intermediate(): x = 2 def inner(): global x in outer x = 42 inner() print x # prints 2 intermediate() print x # prints 42

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

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

Could this be made backwards compatible?

Bye, Walter Dörwald



More information about the Python-Dev mailing list