Python complaints

Eric Jacobs x at x.x
Wed Nov 24 17:45:47 EST 1999

Fredrik Lundh wrote:
> note that python already has a special syntax
> for this purpose:
> >>> a = range(20)
> >>> print a[1:20:3]
> Traceback (innermost last):
>   File "<stdin>", line 1, in ?
> TypeError: sequence index must be integer
> (note that you got a type error, not a syntax
> error.  numpy arrays fully support this syntax).
> in other words, you don't have to be guido to
> realize that something like:
>     for i in [1:20:3]:
>         ...
> could be the right way to do it in Python.  in
> fact, it's already on the list for 2.0:

I don't know if I like that syntax. Taking a slice
of what? If I had to replace range, I'd go with:

   for i in Int[1:20:3]:

Here Int is an object that represents a list of all
integers. We take a slice of it... and get exactly
what we expect.

Either way, the semantics of lists with an infinite
number of elements or negative indices would have
to be cleared up somewhat. That would be a good

More information about the Python-list mailing list