[Python-Dev] Re: d = {}; d[0:1] = 1; d[0:1] = 2; print d[:]

Jeremy Hylton jeremy@alum.mit.edu
Thu, 1 Mar 2001 11:37:53 -0500 (EST)


>>>>> "RT" == Robin Thomas <robin.thomas@starmedia.net> writes:

  RT> Using Python 2.0 on Win32. Am I the only person to be depressed
  RT> by the following behavior now that __getitem__ does the work of
  RT> __getslice__?

You may the only person to have tried it :-).

  RT> Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32
  >>> d = {}
  >>> d[0:1] = 1
  >>> d
  {slice(0, 1, None): 1}

I think this should raise a TypeError (as you suggested later).

>>> del d[0:1]
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: object doesn't support slice deletion

Jeremy