@contextlib.contextmanager<EOL>def saved_cwd():
saved = os.getcwd()<EOL>try:<EOL><INDENT>yield<EOL><DEDENT>finally:<EOL><INDENT>os.chdir(saved)<EOL><DEDENT>
Context manager to restore previous working directory.