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

Chris Barker chris.barker at noaa.gov
Sat Feb 14 06:26:00 CET 2015


On Fri, Feb 13, 2015 at 9:11 PM, Greg Ewing <greg.ewing at 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 at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150213/66797fbe/attachment.html>


More information about the Python-ideas mailing list