copy on write

Ethan Furman ethan at stoneleaf.us
Fri Jan 13 13:40:47 EST 2012


Steven D'Aprano wrote:
> Normally this is harmless, but there is one interesting little glitch you 
> can get:
> 
>>>> t = ('a', [23])
>>>> t[1] += [42]
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> TypeError: 'tuple' object does not support item assignment
>>>> t
> ('a', [23, 42])


There is one other glitch, and possibly my only complaint:

--> a = [1, 2, 3]
--> b = 'hello, world'
--> a = a + b
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
TypeError: can only concatenate list (not "str") to list
--> a += b
--> a
[1, 2, 3, 'h', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd']

IMO, either both + and += should succeed, or both should fail.

~Ethan~



More information about the Python-list mailing list