[Python-3000] Allowing slice syntax in more places

Guido van Rossum guido at python.org
Thu May 11 07:05:03 CEST 2006


The problem is that it's a slippery slope. I think Paul Dubois once
proposed this too, but not much came of it. Once you can write
foo(1:10), why not x = (1:10); and then why not x = 1:10. But you
can't have "if x == 1:10: ..." because the first colon would be
ambiguous. So you'd end up with even more complicated rules about when
you need to parenthesize.

In the end the problem is solvable, but the cost is considerable, and
frankly, outside Numeric (or is it NumPy now?), there isn't a lot of
demand. So you're asked to put up with slice(1, 10) instead of (1:10),
and that's not so bad.

--Guido

On 5/10/06, Travis E. Oliphant <oliphant.travis at ieee.org> wrote:
>
> I'm sorry if this has been discussed before.
>
> One of the things that is really nice about slice syntax is the ability
> to construct slice objects to pass to __getitem__  using []
>
> Would it be possible to extend the syntax so that slice syntax is
> acceptable in more places in Python?  In particular function calls would
> be a very useful addition.  Thus,
>
> myfunc(3:4:0.5, 1:5)
>
> would produce the equivalent bytecode as
>
> myfunc(slice(3,4,0.5), slice(1,5))
>
>
> -Travis
>
>
>
> _______________________________________________
> Python-3000 mailing list
> Python-3000 at python.org
> http://mail.python.org/mailman/listinfo/python-3000
> Unsubscribe: http://mail.python.org/mailman/options/python-3000/guido%40python.org
>


-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list