Asked about Errors, files and modules

Why use with when opening a file?

An answer that works

It closes the file automatically when the block ends, even if an exception is raised inside it. Without it, a failure partway through can leave the file open.

Reading an answer is not being able to give one. The section that teaches this is Errors, files and modules, 4 hours of Python.

Learn this properly