Return value of an assignment statement?

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Sun Feb 24 09:03:56 CET 2008


On Sat, 23 Feb 2008 22:44:30 +0000, Tim Roberts wrote:

> 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>
> 
> Usually, but there's an exception for lists, which a specific
> implementation for += that calls "append".  Or do I misunderstand you?

Terry Reedy showed the "tuple proof", here's the read only property case::

 class A(object):
     def __init__(self):
         self._data = list()
    
     @property
     def data(self):
         return self._data

 a = A()
 a.data += [42]

Output::

 Traceback (most recent call last):
   File "test.py", line 25, in <module>
     a.data += [42]
 AttributeError: can't set attribute

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list