Python Context Managers
Sometimes it's helpful to wrap some code in a given context. Either the code requires some resource from the context, or the context adds some aspect to the code.
Python provides with statement to create a context for the followed block of code.
with context_manager:
# this block runs within the …