Note: I am aware of the
with open('f1') as f1, open('f2') as f2:
...
syntax. This is a different question.
Given a list of strings file_names
is there a way using with
/as
to open every file name in that using a single line. Something such as:
with [open(fn) for fn in file_names] as files:
# use the list of files
which of course doesn't work as it attempts to use the context manager on a list. The length of the list may not be known until run-time, such as sys.argv[1:]