with open(path_to_file, mode='r') as handle:
out = open("", 'w')
for line in handle:
if not "|CA" and "|CO" and "|CT" in line:
out.write(line)
out.close()
When I run it, it only prints out the information that is associated to CT. I want to see the information for CA, CO and CT.
>Solution :
That expression is interpreted as:
if (not "|CA") and ("|CO") and ("|CT" in line):
not "|CA" will never be true, so the if statement should never be taken. If you want lines where ANY of those are present, then you want:
if "|CA" in line or "|CO" in line or "|CT" in line: