@contextmanager
def cd(path):
    cwd = os.getcwd()
    os.chdir(path)
    try:
        yield
    finally:
        os.chdir(cwd)
Context manager for temporary CWD
dataset/ETHPy150Open jupyterhub/jupyterhub/tools/tasks.py/cd