mardi 6 février 2018

Multiple conditions using if not in

I am parsing a plain text file that has several pieces of information in different lines. I use the code as follow:

if not "mystring" in line: continue
queryA = line.split(':')
queryB = line.split('=')
print(queryA, queryB)

Output:
queryA queryB

Now, this is my first line(in the file), I want to go to another line which has a different condition and retrieve few pieces. When I do the following:

if not "mystring" in line: continue
queryA = line.split(':')
queryB = line.split('=')
print(queryA, queryB)
if not "my 2nd string" in line: continue
queryC = line.split(':')
queryD = line.split('=')
print(queryC, queryD)

Output:
queryA

I want to see this output:

queryA queryB queryC queryD

What would be a better way to make this better and prints all the statements?

Aucun commentaire:

Enregistrer un commentaire