[Python-Dev] Dafanging the find() gotcha

Patrick K. O'Brien pobrien@orbtech.com
Mon, 5 Aug 2002 18:36:48 -0500


[Patrick K. O'Brien]
>
> I don't see the logic in this and I couldn't find anything in the docs to
> explain this behavior. I'm guessing this is old hat for most of you, but I
> find this a bit surprising myself.

This one is even more fun. (Apologies in advance if I'm pouring salt on old
wounds.)

>>> s = 'help'
>>> s.rfind('')
4
>>> s[s.rfind('')]
Traceback (most recent call last):
  File "<input>", line 1, in ?
IndexError: string index out of range
>>>

--
Patrick K. O'Brien
Orbtech
-----------------------------------------------
"Your source for Python programming expertise."
-----------------------------------------------
Web:  http://www.orbtech.com/web/pobrien/
Blog: http://www.orbtech.com/blog/pobrien/
Wiki: http://www.orbtech.com/wiki/PatrickOBrien
-----------------------------------------------