Does the following syntax close the file:
lines = [line.strip() for line in open(\'/somefile/somewhere\')]
Bonus points if you can demonstr
It will not. A context manager can be used to close it automatically. For example:
with open('/somefile/somewhere') as handle: lines = [line.strip() for line in handle]