Bug in string.find; was: Re: Proposed PEP: New style indexing,
I don't think my proposal breaks historic Python code, and I
don't think it has the same kind of unfortunate subtle
consequences as the current indexing scheme. You may think the
wart is tiny, but the duct-tape* is available so let's cure it.[*] http://www.google.com/search?as_q=warts+%22duct+tape%22
In this case, so that errors are caught as close to their
occurrence as possible. I see no good reason for the following
to happily print 'y'.
s = 'buggy' print s[s.find('w')]
The bug that got me was what a slice object reports as the
'stop' bound when the step is negative and the slice includes
index 0. Took me hours to figure out why my code was failing.
The double-meaning of -1, as both an exclusive stopping bound
and an alias for the highest valid index, is just plain whacked.
Unfortunately, as negative indexes are currently handled, there
is no it-just-works value that slice could return.
--
--Bryan
|