TFBlogs_2017
TFBlogs_2017 copied to clipboard
file close in with scope
with open(file, "wb") as f:
f.write(data)
f.close()
Why use f.close() in with scope? To my understanding, 'with' syntax wll do release task by itself. Am I right?
Yes with
will close the file, so f.close()
is not required.
see this to know how deep this rabbit hole goes - http://blog.lerner.co.il/dont-use-python-close-files-answer-depends/