[Python-Dev] replacing 'global'
Just van Rossum
just at letterror.com
Sat Oct 25 19:09:12 EDT 2003
It seems noone liked (or remembered) an idea I proposed last february,
but I'm going to repost it anyway:
How about adding a "rebinding" operator, for example spelled ":=":
a := 2
It would mean: bind the value 2 to the nearest scope that defines 'a'.
A better summary by someone else who liked it:
Advantages: no declarative statement (I don't like global much to begin
with, but much less for scope declarations other that what it means
now). It's a nice addition to the current scoping rule: an assignment IS
a scope declaration.
Possible disadvantage: you can only rebind to the nearest scope that
defines the name. If there's a farther scope that also defines that name
you can't reach that. But that's nicely symmetrical with how _reading_
values from nested scopes work today, shadowing is nothing new.
Ideally, augmented assignments would also become "rebinding". However,
this may have compatibility problems.
More information about the Python-Dev