Have to try

Jason Orendorff jason at jorendorff.com
Sun Feb 17 05:07:31 CET 2002


Rick Hamilton writes:
> I want to search that string for the occurrence of a sub string.
> I have tried 
> Find(s,sub)
> Rfind
> MyString.find(sub)

It looks like you're using an extra-old version of Python,
because mystring.find(sub) really should work.
  http://www.python.org/doc/current/lib/string-methods.html

>>> x = "lovely spam, wonderful spam!"
>>> x.find('spam')
7
>>> x.find('food')
-1

So you must be using Python 1.6 or earlier.  Try this.
  http://www.python.org/doc/current/lib/module-string.html

>>> import string
>>> string.find(x, 'spam')
7

## Jason Orendorff    http://www.jorendorff.com/




More information about the Python-list mailing list