Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #70066
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Subject | Re: Method(s) called by square brackets, slice objects |
| Date | 2014-04-10 18:20 -0400 |
| References | <74d6fb5c-baca-4606-9fa8-66238a561e0c@googlegroups.com> <a059f84b-e5b0-4482-9dd5-4489ec0d2563@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.9151.1397168450.18130.python-list@python.org> (permalink) |
On 4/10/2014 2:52 PM, John Ladasky wrote: > Thanks to both Ethan and Steven for their replies. > > Steven: I was trying to use the interpreter and wasn't getting results that I understood -- because I didn't know that __getslice__ was simply gone in Python 3. I implemented a __getslice__ method in my subclass that never got called. > > Ethan: I saw that slice objects were being sent to __getitem__, but that confused me as I thought that its purpose, as implied by the method name, was to return a SINGLE item. A slice is a single sequence object. Sequences can result from any of index lookup, key lookup, or slicings. The backstory is that slicing originally supported only start and stop positions. The 3 __xyzslice__ had separate start and stop parameters instead of the 1 index/key parameter of __xyzitem__. Strides and the slice class were introduced for the benefit of numerical python. When they were 'mainstreamed' into regular python, the __xyzslice__ methods were deprecated (in 2.0) as a single slice object can just as well be passed to __xyzitem__. -- Terry Jan Reedy
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Method(s) called by square brackets, slice objects John Ladasky <john_ladasky@sbcglobal.net> - 2014-04-09 13:24 -0700
Re: Method(s) called by square brackets, slice objects Ethan Furman <ethan@stoneleaf.us> - 2014-04-09 13:34 -0700
Re: Method(s) called by square brackets, slice objects Steven D'Aprano <steve@pearwood.info> - 2014-04-10 02:52 +0000
Re: Method(s) called by square brackets, slice objects John Ladasky <john_ladasky@sbcglobal.net> - 2014-04-10 11:52 -0700
Re: Method(s) called by square brackets, slice objects Terry Reedy <tjreedy@udel.edu> - 2014-04-10 18:20 -0400
csiph-web