oddness in string.find(sub,somestring)

MyHaz support.services.complaints at gmail.com
Wed Mar 30 06:43:49 EST 2005


OK i find this a quark in string.find that i think needs some
consideration.

Normally if a substring is not in the searched_string then string.find
returns -1 (why not len(searched_string) + 1, i don't know but
nevermind that) but what if a searched_string == '' ? Then
string.find(substring,searched_string) == 0 ?

example:

>>> import string
>>> searched_string="abcdefg"
>>> substring="123"
>>> print string.find(substring,searched_string)
-1
>>> searched_string=""
>>> print string.find(substring,searched_string)
0
>>> 


why would this be? And when is someone going to fix it :P


- Haz




More information about the Python-list mailing list