Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail From: Mel Newsgroups: comp.lang.python Subject: Re: bug in str.startswith() and str.endswith() Followup-To: comp.lang.python Date: Thu, 26 May 2011 21:07:12 -0400 Organization: Aioe.org NNTP Server Lines: 34 Message-ID: References: Reply-To: mwilson@the-wire.com NNTP-Posting-Host: V7j4zcmtGzEmG1C7HjXFbg.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Complaints-To: abuse@aioe.org User-Agent: KNode/4.4.8 X-Notice: Filtered by postfilter v. 0.8.2 Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:6356 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 "", line 1, in > 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? It's a wart at the very least. The same thing happened in Python2 with range and xrange; there seemed no way to explicitly pass "default" arguments. Mel.