@contextlib.contextmanager
def save_cwd():
 original_cwd = os.getcwd()
 try:
  (yield)
 finally:
  os.chdir(original_cwd)

@ contextlib . contextmanager def save_cwd ( ) : original_cwd = os . getcwd ( ) try : ( yield ) finally : os . chdir ( original_cwd )
context manager that saves the current working directory .