@contextmanager
def inside_dir(dirpath):
 old_path = os.getcwd()
 try:
  os.chdir(dirpath)
  (yield)
 finally:
  os.chdir(old_path)

@ contextmanager def inside_dir ( dirpath ) : old_path = os . getcwd ( ) try : os . chdir ( dirpath ) ( yield ) finally : os . chdir ( old_path )
execute code from inside the given directory .