Does the following syntax close the file:
lines = [line.strip() for line in open(\'/somefile/somewhere\')]
Bonus points if you can demonstr
This is possible to read and close a file in list comprehension using the more_itertools library1:
import more_itertools as mit
lines = [line.strip() for line in mit.with_iter(open("/somefile/somewhere"))]
Note more_itertools is a third-party package. Install via pip install more_itertools.
See also the documentation for more on more_itertools.with_iter.