questions regarding assignement and copy
Christopher Barker
Chris.Barker at noaa.gov
Thu Oct 19 17:00:09 EDT 2006
Robert Kern wrote:
> From the reference manual:
>
> http://docs.python.org/ref/augassign.html
>
> """An augmented assignment expression like x += 1 can be rewritten as x = x + 1
> to achieve a similar, but not exactly equal effect. In the augmented version, x
> is only evaluated once. Also, when possible, the actual operation is performed
> in-place, meaning that rather than creating a new object and assigning that to
> the target, the old object is modified instead."""
I've always thought this was a mistake -- it is a source of weird errors
and bugs. AFAIC, the augmented assignments should ONLY work with mutable
objects, and ALWAYS do the operation in place.
But then you couldn't write:
i = 1
i += 1
Because python numbers are immutable. I think the problem here is that
augmented assignment is solving two distinct problems: in place
operations and nice syntax for incrementing.
Oh well, it's not that big a deal, and usually the confusion causes
errors that show up right away.
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
More information about the NumPy-Discussion
mailing list