Reputation: 13
I am performing some data validation and cleanup using Python, and I have run into a logical error in some boolean comparisons that I am performing. I have a lookup table that needs to be cleaned up, so I am comparing range values to confirm that there is no overlap between sets of values. All list values have been fed in from a CSV file.
The code:
print >>f2, "Filter logic II for " + myKey[0] + " " + myKey[1] + " " + myKey[2] + ":"
print >>f2, "outerRow[3] " + outerRow[3] + " >= innerRow[3] " + innerRow[3] + " and outerRow[3] " + outerRow[3] + " <= innerRow[4]" + innerRow[4] + " OR outerRow[4] " + outerRow[4] + " >= innerRow[3] " + innerRow[3] + " and outerRow[4] " + outerRow[4] + " <= innerRow[4]" + innerRow[4]
if ((outerRow[3] >= innerRow[3]) and (outerRow[3] <= innerRow[4])) or ((outerRow[4] >= innerRow[3]) and (outerRow[4] <= innerRow[4])):
Test2 = True
print >>f2, "Filter logic II = True"
else:
Test1 = False
print >>f2, "Filter logic II = False"
Which yields results after the first run:
*Filter logic II for XYZ KEY123 PRE:
outerRow[3] 0 >= innerRow[3] 80 and outerRow[3] 0 <= innerRow[4]100 OR outerRow[4] 79 >= innerRow[3] 80 and outerRow[4] 79 <= innerRow[4]100
Filter logic II = False*
But this (unexpected) result after the second run:
*Filter logic II for 080570BD 1998 VA PRE:
outerRow[3] 80 >= innerRow[3] 0 and outerRow[3] 80 <= innerRow[4]79 OR outerRow[4] 100 >= innerRow[3] 0 and outerRow[4] 100 <= innerRow[4]79
Filter logic II = True*
Where am I going wrong in the logical comparison? I've stared a this a bit too long, figured I see if I could get an assist from the world wide network.
Upvotes: 1
Views: 470
Reputation: 25444
Try to convert the data into an int
. This is from an interactive Python shell:
>>> "100" <= "79"
True
>>> 100 <= 79
False
>>> int("100") <= int("79")
False
Upvotes: 3