[Python-ideas] More useful slices

Chris Angelico rosuav at gmail.com
Sun Feb 1 21:38:52 CET 2015


On Mon, Feb 2, 2015 at 5:13 AM, Thomas Kluyver <thomas at kluyver.me.uk> wrote:
> Iterating over a slice object would work like you were lazily taking that
> slice from itertools.count() - i.e. iter(a:b:c) would be equivalent to
> islice(count(), a, b, c). This would also mean that (3:) would have a
> logical meaning without having to modify range objects to support an
> optional upper bound. I don't see any logical way to iterate over a slice
> defined with negative numbers (e.g. (-4:)), so presumably iter(-4:) would
> raise an exception.

If you're going to start defining things in terms of
itertools.count(), I'd prefer to first permit a range object to have
an infinite upper bound, and then define everything in terms of a
sliced range - range objects already support clean slicing.

Is there any particular reason for range objects to disallow infinite
bounds, or is it just that nobody's needed it?

ChrisA


More information about the Python-ideas mailing list