Re: Python 3: range objects cannot be sliced
On 1/16/2009 3:13 PM Alan G Isaac apparently wrote: It is documented: http://docs.python.org/3.0/library/stdtypes.html#sequence-types-str-bytes-bytearray-list-tuple-range But then again, the opposite is also documented, since `range` is a sequence type. Quoting: Sequences also support slicing ... Some sequences also support “extended slicing” Is this a documentation bug, or a bug in `range`? (I'd think the latter.) Cheers, Alan Isaac -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3: range objects cannot be sliced
On Jan 25, 2:28 pm, Alan G Isaac alan.is...@gmail.com wrote: On 1/16/2009 3:13 PM Alan G Isaac apparently wrote: It is documented: http://docs.python.org/3.0/library/stdtypes.html#sequence-types-str-b... But then again, the opposite is also documented, since `range` is a sequence type. Quoting: Sequences also support slicing ... Some sequences also support “extended slicing” Is this a documentation bug, or a bug in `range`? (I'd think the latter.) Cheers, Alan Isaac Where does the documentation say that range objects are sequences? They're iterables. Michael Foord -- http://www.ironpythoninaction.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3: range objects cannot be sliced
Fuzzyman wrote: On Jan 25, 2:28 pm, Alan G Isaac alan.is...@gmail.com wrote: On 1/16/2009 3:13 PM Alan G Isaac apparently wrote: It is documented: http://docs.python.org/3.0/library/stdtypes.html#sequence-types-str-b... But then again, the opposite is also documented, since `range` is a sequence type. Quoting: Sequences also support slicing ... Some sequences also support “extended slicing” Is this a documentation bug, or a bug in `range`? (I'd think the latter.) No range slicing is intended. Where does the documentation say that range objects are sequences? They're iterables. Range objects (2.x xrange objects) were more sequence-like in 2.x. 3.0 doc still says There are five sequence types: strings, byte sequences, byte arrays, lists, tuples, and range objects (the miscount has already been reported.) I added a note to http://bugs.python.org/issue4966 suggesting that ranges be removed from the sequence section. I made several other suggestions for improving this sections. Supportive comments might help get action. tjr -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3: range objects cannot be sliced
On Jan 26, 12:08 pm, Terry Reedy tjre...@udel.edu wrote: Fuzzyman wrote: On Jan 25, 2:28 pm, Alan G Isaac alan.is...@gmail.com wrote: On 1/16/2009 3:13 PM Alan G Isaac apparently wrote: It is documented: http://docs.python.org/3.0/library/stdtypes.html#sequence-types-str-b... But then again, the opposite is also documented, since `range` is a sequence type. Quoting: Sequences also support slicing ... Some sequences also support “extended slicing” Is this a documentation bug, or a bug in `range`? (I'd think the latter.) No range slicing is intended. Where does the documentation say that range objects are sequences? They're iterables. Range objects (2.x xrange objects) were more sequence-like in 2.x. 3.0 doc still says There are five sequence types: strings, byte sequences, byte arrays, lists, tuples, and range objects (the miscount has already been reported.) I added a note to http://bugs.python.org/issue4966 suggesting that ranges be removed from the sequence section. I made several other suggestions for improving this sections. Supportive comments might help get action. I agree the docs need to be fixed; it's not very sequency at all. Other comments: * This error message should not use the s-word, but this may be unavoidable: range(10)[1:3] Traceback (most recent call last): File stdin, line 1, in module TypeError: sequence index must be integer, not 'slice' * It would be good if the docs said more about what it is meant to be used for, apart from the obvious for item in a_range. You can subscript a range, not that it's very useful: range(10)[7] 7 It has neither next() nor __next__() method, and appears to be reusable (which is good, IMO): x = range(10) x.next() Traceback (most recent call last): File stdin, line 1, in module AttributeError: 'range' object has no attribute 'next' x.__next__() Traceback (most recent call last): File stdin, line 1, in module AttributeError: 'range' object has no attribute '__next__' list(x) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] list(x) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] It is immutable, and thus can be hashed ... use case? Cheers, John -- http://mail.python.org/mailman/listinfo/python-list
Python 3: range objects cannot be sliced
Is the behavior below expected? Documented? (The error msg is misleading.) Thanks, Alan Isaac x = range(20) s = slice(None,None,2) x[s] Traceback (most recent call last): File stdin, line 1, in module TypeError: sequence index must be integer, not 'slice' -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3: range objects cannot be sliced
On Jan 16, 5:45 pm, Alan G Isaac alan.is...@gmail.com wrote: Is the behavior below expected? Documented? (The error msg is misleading.) Thanks, Alan Isaac x = range(20) s = slice(None,None,2) x[s] Traceback (most recent call last): File stdin, line 1, in module TypeError: sequence index must be integer, not 'slice' Well, it has the same behaviour as the iterator returned by xrange in Python 2.X - so expected I guess. The error message is also the same in Python 2.X. Michael Foord -- http://www.ironpythoninaction.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3: range objects cannot be sliced
Alan G Isaac alan.is...@gmail.com writes: x = range(20) s = slice(None,None,2) x[s] Traceback (most recent call last): File stdin, line 1, in module TypeError: sequence index must be integer, not 'slice' range is an iterator now. Try itertools.islice. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3: range objects cannot be sliced
On 1/16/2009 1:15 PM Paul Rubin apparently wrote: range is an iterator now. Try itertools.islice. Well yes, it behaves like xrange did. But (also like xrange) it supports indexing. (!) So why not slicing? I expected this (to keep it functionally more similar to the old range). Alan Isaac -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3: range objects cannot be sliced
Alan G Isaac schrieb: On 1/16/2009 1:15 PM Paul Rubin apparently wrote: range is an iterator now. Try itertools.islice. Well yes, it behaves like xrange did. But (also like xrange) it supports indexing. (!) So why not slicing? I expected this (to keep it functionally more similar to the old range). The old range function returned a list. If you need the old functionality you can use list(range(...))[]. Why do you want to slice a range anyway? The range type supports a start, stop and step argument. Christian -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3: range objects cannot be sliced
It is documented: http://docs.python.org/3.0/library/stdtypes.html#sequence-types-str-bytes-bytearray-list-tuple-range -- http://mail.python.org/mailman/listinfo/python-list