[Python-Dev] Customization docs

Paul Svensson paul-python@svensson.org
Sat, 1 Jun 2002 10:17:50 -0400 (EDT)


On Sat, 1 Jun 2002, Guido van Rossum wrote:

>> > > How does Python decide that sequence elements are immutable?
>> >
>> > Huh?  It doesn't.  If they were mutable, had you expected something
>> > else?
>>
>> Actually, yes. I had expcected that Python would know it didn't need
>> to "put the thing back in", since the thing gets modified in
>> place. Knowing that it doesn't work that way clears up a lot.
>
>Still, I don't understand which other outcome than [1, 6, 5] you had
>expected.

Well, _I_ would have expected this to work:

	Python 2.1 (#4, Jun  6 2001, 08:54:49)
	[GCC 2.95.2 19991024 (release)] on linux2
	Type "copyright", "credits" or "license" for more information.
	>>> x = ([],[],[])
	>>> x[1] += [1]
	Traceback (most recent call last):
	  File "<stdin>", line 1, in ?
	TypeError: object doesn't support item assignment

Given that the object x[1] can be (and is) modified in place,
I find this behaviour quite counter-intuitive,
specially considering:

	>>> z = x[1]
	>>> z += [2]
	>>> x
	([], [1, 2], [])


		/Paul