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

Donn Cave donn at u.washington.edu
Fri Jun 22 21:16:08 CEST 2001


Quoth Chris Barker <chrishbarker at home.net>:
| 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.
|
| YEECCHHH!!!
|
| 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 -

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

   try:
       v = x[k]
   except KeyError:
       ...

	Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list