
On 05/10/2011 19:33, Ron Adam wrote:
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.
None will be rejected as an index, but not as part of a slice:
s = "abcdef" s[None : 4] 'abcd' s[4 : None] 'ef'
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.