python: Context Manager

from contextlib import contextmanager
 
@contextmanager
def Open(file, mode):
    f = open(file, mode)
    yield f
    f.close()
 
@contextmanager
def elapsed_time(comment="") -> float:
    start = time.perf_counter()
    yield lambda: time.perf_counter() - start