Newbie question on Re module

Skip Montanaro skip at pobox.com
Sat Jan 4 10:52:42 EST 2003


    Tom> Andrew McGregor wrote:
    >> if str.index('binaries') == -1:
    >>   # then str did not contain the word.

    Tom> Python 2.2 doesn't return -1 when string.index fails; it raises a
    Tom> ValueError exception. Are there older versions of Python that
    Tom> return -1?

Nope.  Should be str.find().

Also, note that str() is the constructor for strings (resides in the builtin
namespace) and is probably not the best choice for a local variable.  It's
one you're likely to need from time to time.






More information about the Python-list mailing list