Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #6363
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Subject | Re: bug in str.startswith() and str.endswith() |
| Date | 2011-05-26 23:00 -0400 |
| References | <4DDEE1C8.6010107@stoneleaf.us> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2141.1306465246.9059.python-list@python.org> (permalink) |
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 | Next — Next in thread | Find similar | Unroll 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