Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

and/or statement only prints out 1 output but I need all of them, python

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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:
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading