don't understand error message

ChrisBarker Chris.Barker at
Wed Sep 18 14:42:11 EDT 2002

Manuel Hendel wrote:
> if domainfield in domain:
>     domainlines.append(line)
> [....]
> This should work if the domainfield and domain got the following
> values, shouldn't it?
> domainfield =
> damain =

Nope. the "in" operator looks for an itme in a sequence. a string is a 
sequence of charactors, so you can only do something like:

if 'f' in 'a long string'

but not:

if 'this' in 'a long string'

what you want is one of the string methods:

if domain.find(domainfield) >= 0 :

string.find() returns the index of the substring if it finds it, and -1 
otherwise. Since 0 is a valid index (and so is -1) you have to check if 
the index >= 0 to see if it is found.


Christopher Barker, Ph.D.
NOAA/OR&R/HAZMAT         (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at

More information about the Python-list mailing list