In another answer here that uses contextlib to define a custom "open" function for use with with
, contextmanager
from contextlib is used to define a function that handles opening and streaming of data and finally closing of the stream.
In learning about this, I see there is also a closing
function that seems to work similarly, with a specific focus on closing the stream when done.
I understand how the contextmanager
construction presented works (explicitly closing the stream as necessary), but I wonder if it is incomplete - for correctness (and to be Pythonic), should closing
be involved as well, or preferred?
Edit: that answer I referred to currently calls fh.close() - I am wondering if somehow closing
ought to be involved here in some way instead of that. The documentation on contextlib
didn't help me in this either-or-both question in the first place, thus this question.