[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'.

Original post:
http://mail.python.org/pipermail/python-dev/2003-February/032764.html

A better summary by someone else who liked it:
http://groups.google.com/groups?selm=mailman.1048248875.10571.python-
list%40python.org

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.

Just



More information about the Python-Dev mailing list