code: def work_in(dirname=None):
      
      curdir = os.getcwd()
      try:
          if dirname is not None:
              os.chdir(dirname)
          yield
      finally:
          os.chdir(curdir)
docs: Context manager version of os.chdir.
  
      When exited, returns to the working directory prior to entering.