I'm trying to execute an if loop inside a program to extract some values. But I only want to extract them if the following is true,

if ((letter in lines) == (letters in data)) and ((nr in       lines) == (nr in data))
    dt = a*c
    outfile.write(dt + '\n')
    dt = 0
    outfile.write(dt + '\n')

I have read in a file with a for loop and thats where lines comes from and also read in another file with a for loop, but underneath the first one. So lines and data are just different files I want to compare.

Does anyone have a suggestion on how to write the if loop with this many arguments? I always want write the results (i.e. dt) to outfile and save it there.


Edited by sofia85: n/a

5 Years
Discussion Span
Last Post by woooee

First have you tried difflib or something like it, as this has to have already been done by someone? If you are using readlines to read the files or reading the recs into a list, we don't know, then these conditions will never be true, because letter or letters does not equal one complete line, which is what "in" is looking for in a list. You can break this down

## what does this mean?  Is it found at all? is it found on the same line? 
# is it found at the same postion on the same line??
print "looking for", letter, lines
x = letter in lines
y = letters in data
if x == y:

Edited by woooee: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.