
On Wed, 2011-10-05 at 08:06 -0700, Ethan Furman wrote:
Ron Adam wrote:
I really don't like the '-1' for a not found case. They just get in the way.
If len(s) was the not found case, you get a value that can be used in a slice without first checking the index, or catching an exception.
So every time we want to know if s.find() failed, we have to compare to len(s)?
I think probably None would have been better than -1. At least then you will get an error if you try to use it as an index.
The problem with len(s) as a failure, is when you consider rfind(). It should return 1 before the beginning, which coincidentally it does, but you still can't use it as a slice index because it will give you 1 from the end instead.
So until we find a another way to do negative sequence indexing. It won't quite work as nice as it should.
Cheers, Ron