Closed kesara closed 5 months ago
It will guarantee that at the exit file will be closed regardless of failure happens during the execution of the
do_work()
or not.
Right, the file handle will be closed, but it'll leave behind an empty file. Whether you care about that is a separate question, I'm just pointing out that you could avoid creating it until you know that you have data to put in it.
It will guarantee that at the exit file will be closed regardless of failure happens during the execution of the
do_work()
or not.Right, the file handle will be closed, but it'll leave behind an empty file. Whether you care about that is a separate question, I'm just pointing out that you could avoid creating it until you know that you have data to put in it.
Good point. Yeah, this could be better.
That's where context managers come in handy eh? It will guarantee that at the exit file will be closed regardless of failure happens during the execution of the
do_work()
or not.