@contextlib.contextmanager
def temp_chdir(path):
  saved_dir = os.getcwd()
  try:
    os.chdir(path)
    yield
  finally:
    os.chdir(saved_dir)
Usage: with temp_chdir(path):
dataset/ETHPy150Open googlei18n/nototools/nototools/tool_utils.py/temp_chdir