Background
I use assert statement to check if certain files in a list exist in my computer, then I would like to do further work if these files are all there.
I've referenced to this thread, so I do something like this:
from pathlib import Path
# The list containing several filepaths
files = ['folder/file1', 'folder/file2', 'folder/file3']
# check if all of these files are exist
assert all(Path(n).exists() for n in files)
# Do something else ...
# ...
This piece of code is runnable. If one file does not exist, the program will raise AssertionError.
Question
Now I would like to all the file(s) that not exist, instead of a simple AssertionError.
Is there any one-liner solution for this?
What I have tried
I've tried the following:
assert all(Path(n).exists() for n in files), f"file {n} not exist!"
Runing this code will report NameError: name 'n' is not defined.