I have an array of files:
part_files = [open(name, "w+") for name in part_names]
...
[part.close() for part in part_files]
I would like to close them in a guaranteed manner even when there is an exception in between.
I am aware of two ways, namely try catch finally
and contextlib.nested
however I'd like to know which is preferred and would work on both 2.7 and 3.0. From what I understand contextlib.nested
is deprecated in 3.0