Another Wart! string.find() [ was: namespace issue? ]
Steven D. Majewski
sdm7g at Virginia.EDU
Fri Jun 22 18:41:08 CEST 2001
On 22 Jun 2001, Donn Cave wrote:
> Given that you can't treat find or index as a boolean, there is
> no fault I can see with its -1 failure return. In fact it would
> be worse if it were false. Usage that doesn't work reliably
> ideally shouldn't work at all, or it's all the harder to diagnose.
That last sentence above is just why I suggested None would be a
better return value. You still can't do "if not string.find(..."
because zero is still a valid return offset, but the problem with
-1 is that it can slip thru since [-1] is a valid string index,
it's valid in a slice expression, and can be added or subtracted
as an offset to another index value, all without giving an exception
anywhere near the error. If you try to use None as an index or add
it to another offset, you get an exception right away.
-- Steve Majewski
More information about the Python-list