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

Donn Cave donn at
Fri Jun 22 15:16:08 EDT 2001

Quoth Chris Barker <chrishbarker at>:
| Andrew Dalke wrote:
|> 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.
| Never raise an exception for a perfectly normal, it will happen all the
| time event.

Sure, but always raise an exception if the caller isn't going
to account for this perfectly normal event.  Exceptions aren't
about frequency.

Similar exception usage is actually somewhat idiomatic in Python -

       i = x.find('#')
       x = x[:i]
   except ValueError:

       v = x[k]
   except KeyError:

	Donn Cave, donn at

More information about the Python-list mailing list