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


Groups > comp.lang.python > #6355

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

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <pavlovevidence@gmail.com>
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; 'mrab': 0.05; 'parameter': 0.05; 'bug.': 0.07; 'end,': 0.07; 'see:': 0.07; 'slice': 0.07; "'this": 0.09; 'arguments,': 0.09; 'integers': 0.09; 'none)': 0.09; 'prefix': 0.09; 'prefix,': 0.09; 'prefixes': 0.09; 'start[,': 0.09; 'subject:()': 0.09; 'tuple': 0.09; 'this:': 0.10; '>>>': 0.12; 'wrote:': 0.14; 'bug?': 0.16; 'end]])': 0.16; 'furman': 0.16; 'message- id:@glegroupsg2000goo.googlegroups.com': 0.16; 'reply- to:addr:comp.lang.python': 0.16; 'subject:() ': 0.16; 'suffix': 0.16; 'suffixes': 0.16; 'to:addr:comp.lang.python': 0.16; 'argument': 0.16; 'traceback': 0.16; '(most': 0.16; 'cc:addr :python-list': 0.17; 'keyword': 0.19; 'subject:skip:s 10': 0.19; 'starts': 0.20; 'header:In-Reply-To:1': 0.21; "aren't": 0.22; 'cc:2**0': 0.22; 'cc:no real name:2**0': 0.23; 'indices': 0.23; 'last):': 0.23; 'optional': 0.23; 'specified': 0.26; 'string': 0.26; 'tried': 0.27; 'position.': 0.29; 'start,': 0.29; 'cc:addr:python.org': 0.30; 'carl': 0.30; 'false.': 0.30; 'none,': 0.30; 'typeerror:': 0.30; 'useless': 0.30; 'looks': 0.31; "can't": 0.32; 'yet': 0.32; 'skip:" 20': 0.33; "i've": 0.33; 'received:209.85.212': 0.34; 'file': 0.34; 'there': 0.35; 'header :User-Agent:1': 0.35; '"",': 0.35; 'using': 0.35; 'test': 0.35; 'skip:. 10': 0.36; 'probably': 0.36; 'none': 0.37; 'beginning': 0.37; 'received:google.com': 0.37; 'received:209.85': 0.37; 'comparing': 0.37; 'thursday,': 0.37; 'pretty': 0.37; 'but': 0.38; 'docs': 0.38; 'subject:: ': 0.38; 'skip:s 20': 0.39; "i'd": 0.39; 'received:209': 0.39; 'stop': 0.62; 'to:addr:googlegroups.com': 0.63; '26,': 0.67; 'header:Reply-To:1': 0.72; 'reply-to:no real name:2**0': 0.72; 'reply-to:addr:googlegroups.com': 0.73
Newsgroups comp.lang.python
Date Thu, 26 May 2011 17:59:07 -0700 (PDT)
In-Reply-To <mailman.2137.1306452453.9059.python-list@python.org>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=76.91.176.167; posting-account=XFEWnwoAAADNO10m3Wcmq_SWdmyZuXff
User-Agent G2/1.0
X-Google-Web-Client true
MIME-Version 1.0
Subject Re: bug in str.startswith() and str.endswith()
From Carl Banks <pavlovevidence@gmail.com>
To comp.lang.python@googlegroups.com
Content-Type text/plain; charset=ISO-8859-1
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
Reply-To comp.lang.python@googlegroups.com
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>
Message-ID <mailman.2139.1306457951.9059.python-list@python.org> (permalink)
Lines 42
NNTP-Posting-Host 82.94.164.166
X-Trace 1306457951 news.xs4all.nl 49174 [::ffff:82.94.164.166]:37501
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:6355

Show key headers only | View raw


On Thursday, May 26, 2011 4:27:22 PM UTC-7, MRAB wrote:
> On 27/05/2011 00:27, 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
> >
> > str.endswith(suffix[, start[, end]])
> > Return True if the string ends with the specified suffix, otherwise
> > return False. suffix can also be a tuple of suffixes to look for. With
> > optional start, test beginning at that position. With optional end, stop
> > comparing at that position.
> >
> > Any reason this is not a bug?
> >
> Let's see: 'start' and 'end' are optional, but aren't keyword
> arguments, and can't be None...
> 
> I'd say bug.

I also say bug.  The end parameter looks pretty useless for .startswith() and is probably only present for consistency with other string search methods like .index().  Yet on .index() using None as an argument works as intended:

>>> "cbcd".index("c",None,None)
0

So it's there for consistency, yet is not consistent.


Carl Banks

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


Thread

Re: bug in str.startswith() and str.endswith() Carl Banks <pavlovevidence@gmail.com> - 2011-05-26 17:59 -0700
  Re: bug in str.startswith() and str.endswith() Duncan Booth <duncan.booth@invalid.invalid> - 2011-05-27 10:31 +0000

csiph-web