Given a list of file names filenames = [...].
Is it possible to rewrite the following list comprehension for I / O security [do_smth(open(filename, 'rb').read()) for filename in filenames]:? Using an operator with, method, .closeor something else.
Another problem statement: is it possible to write an I / O-safe list comprehension for the following code?
results = []
for filename in filenames:
with open(filename, 'rb') as file:
results.append(do_smth(file.read()))
source
share