lundi 6 avril 2020

Run If query multiple times in Python

I have to run an if query multiple times. Now of course I could include the query several times in my code. Is this the clean way? Or should I write this differently?

Here my query

if 'xyc_begin' in content and 'xyc_end' in content:
    file.write('xyc available\n')
else:
    print('xyc not available\n')
    file.write('xyc not available\n')
    file.close()
    sys.exit()

Now I would have to check for abc and def (instead of xyc) and adjust the line in the file accordingly. How do you program this correctly or do you just do several queries?

Aucun commentaire:

Enregistrer un commentaire