Re: [Python-ideas] Adding "+" and "+=" operators to dict

On Fri, Feb 13, 2015 at 9:11 PM, Greg Ewing <greg.ewing@canterbury.ac.nz> wrote:
2) The LHS is a complex expression that you only want
to write out and evaluate once.
Can you give an example of this? how can put an expression in the right hand side?
myobj.dingle.dell[17] += 42
Hmmm -- I guess I need to look up "expression" -- I would have thought of that as a single object -- but yes, name lookups can be expensive, so there may be a win there. But: In this case, this will only work if myobj.dingle.dell is a mutable object. Even if myobj.dingle.dell[17] is imuttable. but if dell is immutable, it won't work even if dell[17] is mutable. So we don't have the full win here. if += was only supported on mutables, then it would be the other way around. Not sure if there is a clear win there. But maybe it is possible to have a kind of hot fix that allows both. -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker@noaa.gov
participants (1)
-
Chris Barker