Suggested feature: slice syntax within tuples (or even more generally)?

stephenwlin at stephenwlin at
Wed Feb 13 20:00:15 CET 2013


Would it be feasible to modify the Python grammar to allow ':' to generate slice objects everywhere rather than just indexers and top-level tuples of indexers?

Right now in Py2.7, Py3.3:
    "obj[:,2]" yields "obj[slice(None),2]"
    "obj[(:,1),2]" is an error, instead of "obj[(slice(None), 1), 2]"

Also, more generally, you could imagine this working in (almost?) any expression without ambiguity:
    "a = (1:2)" could yield "a = slice(1,2)"

See motivating discussion for this at:

There might not be very many use cases for this currently outside of pandas, but apparently the grammar was already modified to allow '...' outside indexers and there's probably even fewer valid use cases for that:
    "e = ..." yields "e = Ellipsis"

Would there be any downside to changing the handling of ':' as well? It might even make the grammar simpler, in some ways, since indexers won't have to be treated specially.

Let me know if you have any thoughts.


More information about the Python-list mailing list