Path: csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: 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; 'mrab': 0.05; '-1,': 0.09; 'behave': 0.09; 'indexes': 0.09; 'sentence': 0.09; 'sub': 0.09; 'substring': 0.09; 'terry': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.10; 'index': 0.13; '*why*': 0.16; 'docstring': 0.16; 'index.': 0.16; 'indexerror:': 0.16; 'notation,': 0.16; 'reedy': 0.16; 'subject: \n ': 0.16; 'subject:parameters': 0.16; 'subject:when': 0.16; 'string': 0.17; 'wrote:': 0.17; 'integer': 0.17; "shouldn't": 0.17; '(in': 0.18; '>>>': 0.18; '"",': 0.22; 'either.': 0.22; 'cc:2**0': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In- Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'creating': 0.26; '(most': 0.27; 'checking': 0.27; 'correct': 0.28; 'subject:/': 0.28; 'received:209.85.212': 0.28; 'behaviour': 0.29; 'case,': 0.29; 'maybe': 0.29; "skip:' 10": 0.30; 'returned': 0.30; 'file': 0.32; 'could': 0.32; 'traceback': 0.33; 'true.': 0.33; 'equal': 0.33; "can't": 0.34; 'received:google.com': 0.34; 'returning': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'should': 0.36; 'does': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'where': 0.40; 'end': 0.40; 'think': 0.40; 'range': 0.60; 'first': 0.61; 'maybe,': 0.84; 'novembre': 0.84; 'received:209.85.212.56': 0.91 Newsgroups: comp.lang.python Date: Wed, 21 Nov 2012 23:01:47 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=158.110.95.152; posting-account=uBCs_goAAABnqb0dwcS_m7_qp7XDdB0G References: <9ecd357d-aaaa-4f4d-a987-a478e92b2052@googlegroups.com> <50ACD7FB.3060906@mrabarnett.plus.com> User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 158.110.95.152 MIME-Version: 1.0 Subject: Re: Inconsistent behaviour os str.find/str.index when providing optional parameters From: Giacomo Alzetta To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: Lines: 36 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1353567717 news.xs4all.nl 6966 [2001:888:2000:d::a6]:38264 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:33790 Il giorno gioved=EC 22 novembre 2012 05:00:39 UTC+1, MRAB ha scritto: > On 2012-11-22 03:41, Terry Reedy wrote: > It can't return 5 because 5 isn't an index in 'spam'. >=20 >=20 >=20 > It can't return 4 because 4 is below the start index. Uhm. Maybe you are right, because returning a greater value would cause an = IndexError, but then, *why* is 4 returned??? >>> 'spam'.find('', 4) 4 >>> 'spam'[4] Traceback (most recent call last): File "", line 1, in IndexError: string index out of range 4 is not a valid index either. I do not think the behaviour was completely = intentional. If find should return indexes than 'spam'.find('', 4) must be = -1, because 4 is not a valid index. If find should behave as if creating th= e slice and checking if the substring is in the slice than 'spam'.find('', = i) should return i for every integer >=3D 4. The docstring does not describe this edge case, so I think it could be impr= oved. If the first sentence(being an index in S) is kept, than it shouldn't say t= hat start and end are treated as in slice notation, because that's actually= not true. It should be added if start is greater or equal to len(S) then -= 1 is always returned(and in this case 'spam'.find('', 4) -> -1). If find should not guarantee that the value returned is a valid index(when = start isn't a valid index), then the first sentence should be rephrased to = avoid giving this idea(and the comparisons in stringlib/find.h should be sw= apped to have the correct behaviour). For example, maybe, it could be "Return the lowest index where substring su= b is found (in S?), such that sub is contained in S[start:end]. ...