Another Wart! string.find() [ was: namespace issue? ]
Andrew Dalke
dalke at acm.org
Thu Jun 21 22:56:44 EDT 2001
Steven D. Majewski wrote:
> It probably *ought* to return None for not found:
> "string"[None] yields an exception:
> "TypeError: sequence index must be integer"
> while "string"[-1] returns "g"
> so a coding error is likely to slip thru without an exception.
...
> I'ld love to see it fixed, however, I suspect that in this case,
> many lines of installed code trumps Computer Programming for Everybody!
>>> print string.find.__doc__
find(s, sub [,start [,end]]) -> in
Return the lowest index in s where substring sub is found,
such that sub is contained within s[start,end]. Optional
arguments start and end are interpreted as in slice notation.
Return -1 on failure.
>>> print string.index.__doc__
index(s, sub [,start [,end]]) -> int
Return the lowest index in s where substring sub is found,
such that sub is contained within s[start,end]. Optional
arguments start and end are interpreted as in slice notation.
Raise ValueError if not found.
>>>
Only difference is what to do when the substring isn't found;
return -1 or raise a ValueError.
Andrew
dalke at acm.org
More information about the Python-list
mailing list