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

Michael Powe michael+gnus at trollope.org
Fri Jun 22 10:18:19 EDT 2001


>>>>> "Andrew" == Andrew Dalke <dalke at acm.org> writes:

    Andrew> 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__
    Andrew> find(s, sub [,start [,end]]) -> in

    Andrew> Return the lowest index in s where substring sub is found,
    Andrew> such that sub is contained within s[start,end].  Optional
    Andrew> arguments start and end are interpreted as in slice
    Andrew> notation.

    Andrew> Return -1 on failure.
    >>>> print string.index.__doc__
    Andrew> index(s, sub [,start [,end]]) -> int

    Andrew>  Return the lowest index in s where substring sub is
    Andrew> found, such that sub is contained within s[start,end].
    Andrew> Optional arguments start and end are interpreted as in
    Andrew> slice notation.

    Andrew>  Raise ValueError if not found.

Pardon the dumb question, but can you test this in a conditional, as
in 

if not string.index(s,sub) : /* and so forth and so on */

mp




More information about the Python-list mailing list