Search notes:

Python standard library: contextlilb.contextmanager

contextmanager is a decorator. With this decorator, a function is turned into a context manager that can be used in a with statement.
from contextlib import contextmanager

@contextmanager
def aResource():

    print('Acquiring a resource')
    try:
       yield

    finally:
       print('releasing the resource')

with aResource():
     print('  do something while the resource is acquired')
Github repository about-Python, path: /standard-library/contextlib/contextmanager.py

Index