What's up with rebinding assignment?
cben at techunix.technion.ac.il
Fri Mar 21 13:13:42 CET 2003
Once upon a time, Just threw in a great (IMHO ;-) idea on pytohn-dev:
The idea was to add am ``:=`` rebinding operator, one that changes a
visible binding without making it local to the current scope::
x = 1
x := 2
would print 2.
Futhermore, augmented assignments can become always rebinding with
almost no breakage of code::
x = 1
x += 1
Currently this makes `x` local to `rebind` and raises an exception
because `x` is not initialized there; so no working code can change
its meaning (unless you do evil locals() manipulations perhaps).
Using ``:=`` (but not augmented assignments) for names that are
already local to the current scope should probably be forbidden -- it
adds nothing and somebody would think it gives write-only access to
This seems a very sound addition that will remove the need for the
ugly singleton-list hack::
x = 
x += 1
My question is: is there a chance this will make it into Python?
Nobody seems to have noticed it... Will a PEP help?
Beni Cherniavsky <cben at tx.technion.ac.il>
More information about the Python-list