Context Managers and Python's with Statement - Real Python
Briefly

The with statement in Python is a quite useful tool for properly managing external resources in your programs.It allows you to take advantage of existing context managers to automatically handle the setup and teardown phases whenever you're dealing with external resources or with operations that require those phases.
Read at Realpython
[
|
]