Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #6363

Re: bug in str.startswith() and str.endswith()

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!selfless.tophat.at!newsfeed.xs4all.nl!newsfeed5.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; 'subject:bug': 0.04; '3.2': 0.05; 'bug.': 0.07; 'end,': 0.07; 'slice': 0.07; 'terry': 0.07; "'this": 0.09; 'integers': 0.09; 'none)': 0.09; 'prefix': 0.09; 'prefix,': 0.09; 'prefixes': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'start[,': 0.09; 'subject:()': 0.09; 'tuple': 0.09; 'pm,': 0.10; 'this:': 0.10; 'wrote:': 0.14; 'end]])': 0.16; 'furman': 0.16; 'reedy': 0.16; 'subject:() ': 0.16; 'traceback': 0.16; '(most': 0.16; 'subject:skip:s 10': 0.19; 'jan': 0.20; 'starts': 0.20; 'header:In-Reply-To:1': 0.21; 'indices': 0.23; 'last):': 0.23; 'optional': 0.23; 'index': 0.25; 'string': 0.26; 'says': 0.27; 'tried': 0.27; 'position.': 0.29; 'start,': 0.29; 'false.': 0.30; 'none,': 0.30; 'typeerror:': 0.30; 'types.': 0.30; 'clearly': 0.32; 'header:X-Complaints-To:1': 0.32; 'to:addr:python-list': 0.33; 'error': 0.33; "i've": 0.33; 'rather': 0.34; 'file': 0.34; 'header:User-Agent:1': 0.35; '"",': 0.35; 'test': 0.35; 'none': 0.37; 'beginning': 0.37; 'comparing': 0.37; 'pretty': 0.37; 'received:org': 0.38; 'docs': 0.38; 'subject:: ': 0.38; 'skip:s 20': 0.39; 'header:Mime-Version:1': 0.39; 'to:addr:python.org': 0.39; 'stop': 0.62
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: bug in str.startswith() and str.endswith()
Date Thu, 26 May 2011 23:00:32 -0400
References <4DDEE1C8.6010107@stoneleaf.us>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host rain.gmane.org
User-Agent Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.17) Gecko/20110414 Lightning/1.0b2 Thunderbird/3.1.10
In-Reply-To <4DDEE1C8.6010107@stoneleaf.us>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
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.2141.1306465246.9059.python-list@python.org> (permalink)
Lines 27
NNTP-Posting-Host 82.94.164.166
X-Trace 1306465246 news.xs4all.nl 49044 [::ffff:82.94.164.166]:45714
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:6363

Show key headers only | View raw


On 5/26/2011 7:27 PM, Ethan Furman wrote:
> I've tried this in 2.5 - 3.2:
>
> --> 'this is a test'.startswith('this')
> True
> --> 'this is a test'.startswith('this', None, None)
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> TypeError: slice indices must be integers or None or have an __index__
> method
>
> The 3.2 docs say this:
>
> str.startswith(prefix[, start[, end]])
> Return True if string starts with the prefix, otherwise return False.
> prefix can also be a tuple of prefixes to look for. With optional start,
> test string beginning at that position. With optional end, stop
> comparing string at that position

To me, that says pretty clearly that start and end have to be 
'positions', ie, ints or other index types. So I would say that the 
error message is a bug. I see so reason why one would want to use None 
rather that 0 for start or None rather than nothing for end.

-- 
Terry Jan Reedy

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: bug in str.startswith() and str.endswith() Terry Reedy <tjreedy@udel.edu> - 2011-05-26 23:00 -0400
  Re: bug in str.startswith() and str.endswith() Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-27 03:27 +0000
  Re: bug in str.startswith() and str.endswith() Mel <mwilson@the-wire.com> - 2011-05-27 09:03 -0400

csiph-web