[Python-Dev] behavior of inplace operations

Jeremy Hylton jeremy@zope.com
Mon, 17 Jun 2002 08:40:30 -0400


>>>>> "DA" == David Abrahams <david.abrahams@rcn.com> writes:

  DA> I guess I am, even if I believed your "as-if" description:

  >>> a = range(12) 
  >>> t0,t1 = a,slice(2,9) 
  >>> t0[t1] = t0[t1] + [666]
  DA> Traceback (most recent call last):
  DA>   File "<stdin>", line 1, in ?
  DA> TypeError: sequence index must be integer

There seem to be many ways to spell this, all quite similar.  And
different versions of Python have different things to say about it.
Current CVS says:

   >>> a = range(12)
   >>> t0,t1 = a,slice(2, 9)
   >>> t0[t1] = t0[t1] + [666]
   Traceback (most recent call last):
     File "<stdin>", line 1, in ?
   ValueError: attempt to assign list of size 8 to extended slice of
   size 7

I suspect this is a bug, since I didn't ask for an extended slice.

   >>> a[2:9] = a[2:9] + [666]
   >>> a
   [0, 1, 2, 3, 4, 5, 6, 7, 8, 666, 9, 10, 11]

Jeremy