New to Python

John Gordon gordon at panix.com
Tue Feb 9 17:11:45 EST 2010


In <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d at posted.grandecom> "Quin" <quindennis at grandecom.net> writes:

> s = f.readline()
> if 'mystring' in s: print 'foundit'
> if 'mystring' not in s: print 'not found'
> if 'mystring' in s:
>     print 'processing'

> this generates output:
> not found
> processing

> so, it doesn't find the substring, but goes into processing code anyway.

I got this output when f contained 'mystring':

  foundit
  processing

And this output when f did not contain 'mystring':

  notfound

I have no idea why it would have worked otherwise for you.  When you posted
your question, did you type the code by hand?  Perhaps you made a mistake.

-- 
John Gordon                   A is for Amy, who fell down the stairs
gordon at panix.com              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"




More information about the Python-list mailing list