Skip to content Skip to sidebar Skip to footer

Python String Comparison Not Matching A Line Read From A File

I have got a text file with keywords in each line like so: foo foo1 ^^^^^^^^^ foo5 foo7 ^^^^^^^^^ is a flag set to break the for loop once reached: keywords = [] with open('ke

Solution 1:

There probably is a line break or other whitespace at the end of the line, so == won't work, unless you trim it first:

if line.strip() == "^^^^^^^^^":

Post a Comment for "Python String Comparison Not Matching A Line Read From A File"