Another Wart! string.find() [ was: namespace issue? ]

Steven D. Majewski sdm7g at Virginia.EDU
Thu Jun 21 23:25:04 EDT 2001


On Thu, 21 Jun 2001, Andrew Dalke wrote:

> >>> 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.


Of course, this introduces a difference in the behavior of 
string.index and list.index ( see the note in other post about
whether strings should even be sequences ... ) and so creates
another pothole for the unwary! 

-- Steve Majewski






More information about the Python-list mailing list