Scope rule pecularities
Greg Ewing
greg at cosc.canterbury.ac.nz
Sun May 9 23:16:16 EDT 2004
Antoon Pardon wrote:
> IMO having operators that should work in place for object that
> are immutable, sound contradictory. Having the following code:
But restricting += etc. to work only on mutables would
mean you wouldn't be able to do things like
x = 42
x += 1
which is a very handy thing to be able to do. The current
semantics are a pragmatic compromise which seems to work
fairly well in most situations.
I suggested once that the assignment could perhaps be
skipped if the __iadd__ method returned the original
object. That would allow a_tuple[i] += something to work
in the case where the object is in-place modifiable.
--
Greg Ewing, Computer Science Dept,
University of Canterbury,
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg
More information about the Python-list
mailing list