Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #32615
| Path | csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'syntax': 0.03; 'string.': 0.04; 'float': 0.05; 'modified': 0.05; 'needed,': 0.05; 'say,': 0.05; 'badly': 0.07; 'builtin': 0.07; 'indexing': 0.07; 'method,': 0.07; 'rejected': 0.07; 'api': 0.09; 'python': 0.09; 'exist.': 0.09; 'integer,': 0.09; 'integers': 0.09; 'it;': 0.09; 'mentions': 0.09; 'objects.': 0.09; 'pep': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'slices': 0.09; 'subclasses': 0.09; 'subject:()': 0.09; 'types:': 0.09; 'underlying': 0.09; 'index': 0.13; 'interfaces': 0.15; 'integers.': 0.16; 'kern': 0.16; 'numpy': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:array': 0.16; 'wrote:': 0.17; 'example.': 0.17; 'integer': 0.17; '(not': 0.20; 'define': 0.20; 'written': 0.20; 'trying': 0.21; 'meant': 0.21; 'interpret': 0.22; 'needed.': 0.23; 'specifically': 0.24; 'header:In-Reply-To:1': 0.25; 'header:User- Agent:1': 0.26; 'am,': 0.27; 'andrew': 0.27; 'header:X-Complaints- To:1': 0.28; 'rest': 0.28; 'all.': 0.28; 'represent': 0.28; 'motivation': 0.29; 'objects': 0.29; "i'm": 0.29; 'checked': 0.30; 'code': 0.31; 'implement': 0.32; 'generally': 0.32; 'could': 0.32; 'goes': 0.33; 'affects': 0.33; 'function.': 0.33; 'int': 0.33; 'prominent': 0.33; 'values.': 0.33; 'to:addr:python-list': 0.33; 'operations': 0.33; 'third': 0.34; 'list': 0.35; 'filter': 0.35; 'generic': 0.35; 'robert': 0.35; 'sequence': 0.35; 'received:org': 0.36; 'really': 0.36; 'but': 0.36; 'wanted': 0.36; 'method': 0.36; 'should': 0.36; 'beyond': 0.37; 'does': 0.37; 'why': 0.37; 'passed': 0.37; 'far': 0.37; 'subject:: ': 0.38; 'sure': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'where': 0.40; 'header:Received:5': 0.40; 'your': 0.60; 'provide': 0.62; 'mentioned': 0.63; 'world': 0.63; 'more': 0.63; 'show': 0.63; 'here': 0.65; 'our': 0.65; 'reasons,': 0.65; 'apologize': 0.67; 'believe': 0.69; '"yes,': 0.84; 'clearly.': 0.84; 'different.': 0.84; 'eco': 0.84; 'ian,': 0.84; 'terrible': 0.84; 'canonical': 0.91 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Robert Kern <robert.kern@gmail.com> |
| Subject | Re: Negative array indicies and slice() |
| Date | Fri, 02 Nov 2012 10:48:50 +0000 |
| References | <509053F2.6020900@r3dsolutions.com> <CALwzidnQ2bUdMp8c0xNomabcLHZBBtr_DYSSzvhz3jqeYNkWkQ@mail.gmail.com> <50912ADC.2020401@r3dsolutions.com> <CALwzid=_1TCQC5JryemVfVpBLWq=qZwy4hRjCPA5ha0vSm3=VA@mail.gmail.com> <50918716.3080305@r3dsolutions.com> <5092833F.4070609@stoneleaf.us> <50925DE6.7020100@r3dsolutions.com> <CALwzidkf6yaPz3C9qUtsUe-a+ojmpJNY0FxhBiykZmm6VssYTQ@mail.gmail.com> <mailman.3170.1351808865.27098.python-list@python.org> <50932c9f$0$29967$c3e8da3$5496439d@news.astraweb.com> <50938AE7.4060705@r3dsolutions.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | 213.1.240.227 |
| User-Agent | Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:16.0) Gecko/20121026 Thunderbird/16.0.2 |
| In-Reply-To | <50938AE7.4060705@r3dsolutions.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3196.1351853351.27098.python-list@python.org> (permalink) |
| Lines | 50 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1351853351 news.xs4all.nl 6958 [2001:888:2000:d::a6]:52747 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:32615 |
Show key headers only | View raw
On 11/2/12 8:57 AM, Andrew Robinson wrote: > Hi Ian, > > I apologize for trying your patience with the badly written code example. All > objects were meant to be ThirdParty(), the demo was only to show how a slice() > filter could have been applied for the reasons PEP357 made index() to exist. > eg: because numpy items passed to __getitems__ via slice syntax [::] were > illegal values. > PEP 357 is the one who specifically mentioned Numpy types -- which is the only > reason I used the name in the example; I could have just as well used a string. > > I am fully aware of what numpy does -- I have used it; modified the fortran > interfaces underneath, etc. > > The index() method, however, affects *all* list objects in Python, not just > Numpy's -- correct? Please forget that PEP 357 mentions slices at all. The motivation for the __index__() method (not index()) goes far beyond slices. I'm not really sure why they are given such a prominent place in the PEP. Let me try to lay out the motivation more clearly. numpy has objects that represent integers but cannot be subclasses of the Python int or long objects because their internal representations are different. These are the width-specific types: uint8, int16, int64, etc. Before __index__() was introduced, all indexing operations in the builtin Python sequence types strictly checked for int or long objects and rejected other objects. We wanted to provide a generic method that third party types could implement to say, "Yes, I really am an integer, here is my value in a canonical representation you can understand." We could not use __int__() for this purpose because it has additional semantics, namely conversion from not-integers to integers. This is why floats are mentioned; they do not generally represent integers but they do define an __int__() method for their conversion to ints via the floor() function. Generally, they should be rejected as indices. With the __index__() method, we have a solution: int16 and the rest get __index__() methods and float doesn't. This is used where an integer index or offset is needed, not just in slices. List indices, file.seek(), mmap.mmap(), etc. The change to use PyIndex_Check() instead of PyInt_Check() was not very difficult or extensive. Even if you were to change the slicing API for your other reasons, __index__() would still be needed. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Re: Negative array indicies and slice() Andrew Robinson <andrew3@r3dsolutions.com> - 2012-11-01 15:25 -0700
Re: Negative array indicies and slice() Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-02 02:14 +0000
Re: Negative array indicies and slice() Andrew Robinson <andrew3@r3dsolutions.com> - 2012-11-02 01:57 -0700
Re: Negative array indicies and slice() Robert Kern <robert.kern@gmail.com> - 2012-11-02 10:48 +0000
csiph-web