@contextmanager
def chdir(new_dir):
    current_dir = os.getcwd()
    os.chdir(new_dir)
    yield
    os.chdir(current_dir)
Chdir to another directory for an operation
dataset/ETHPy150Open koenbok/Cactus/cactus/utils/filesystem.py/chdir