New to Python

Larry Hudson orgnut at yahoo.com
Tue Feb 9 22:09:45 EST 2010


Quin wrote:
> 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.
> 
> This is using IronPython

As others have already said, this _does_ work properly.

But a minor rearrangement is simpler, and IMHO clearer:

if 'mystring' not in s:
     print 'not found'
else:
     print 'foundit'
     print 'processing'

      -=- Larry -=-



More information about the Python-list mailing list