dimanche 29 août 2021

And or operators in one line if statement [closed]

I have the following line of code which I would like to amend with one more condition,

file_names = [f for f in os.listdir(source_dir) if not f.startswith('.')]

so it would also NOT include directories; however, it does not seem to work:

file_names = [f for f in os.listdir(source_dir) if not f.startswith('.') and os.path.isdir]

Is there a way around to keep the expression in one line?

Aucun commentaire:

Enregistrer un commentaire