@contextmanager
def pushd(path):
 cwd = os.getcwd()
 os.chdir(os.path.abspath(path))
 try:
  (yield)
 finally:
  os.chdir(cwd)

@ contextmanager def pushd ( path ) : cwd = os . getcwd ( ) os . chdir ( os . path . abspath ( path ) ) try : ( yield ) finally : os . chdir ( cwd )
context manager that changes to path directory on enter and changes back to os .