Return value of an assignment statement?
Aahz
aahz at pythoncraft.com
Tue Feb 26 13:17:47 EST 2008
In article <62a2asF21dimdU1 at mid.uni-berlin.de>,
Marc 'BlackJack' Rintsch <bj_666 at gmx.net> wrote:
>On Fri, 22 Feb 2008 11:00:17 -0800, Aahz wrote:
>>
>> It's just too convenient to be able to write
>>
>> L += ['foo']
>>
>> without rebinding L.
>
><nitpick>But ``+=`` does rebind.</nitpick>
>
>Doesn't matter in this case but we've had confused programmers asking
>questions here when `L` is a class attribute and it's rebound to the
>instance, or if they tried it on a list in a tuple. Extending a list
>that's a read only property doesn't work either.
Fair point. And in fact the original primary use case for allowing the
target of augmented assignment to return self was NumPy. Being able to
use the simple syntax of augmented assignment instead of method calls in
order to avoid copying huge arrays was a big win. (Which you probably
know, but there are other people reading this thread who don't.)
--
Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/
"All problems in computer science can be solved by another level of
indirection." --Butler Lampson
More information about the Python-list
mailing list