mercredi 3 mars 2021

pythonic way to simplify if clause with multiple values

import os
for file in ['a.txt', 'b.txt', 'c.txt']:
    if not os.path.exists(os.getcwd() + '\\' + file):
        print(fr'{file} is missing')

Basically, I would like to place a.txt, b.txt, c.txt into the os.path.exists function one by one, and then, inside the if clause, I would like to print the message with the file name included. I have no idea how to make it pythonic. I see people write "in" with "if" in one line, but I have no idea how to do that in my case, as I have a print function that uses the value "file" too.

Again, I want to make it efficient, pythonic.

Aucun commentaire:

Enregistrer un commentaire