def work_dir(path):
    '''
    Context menager for executing commands in some working directory.
    Returns to the previous wd when finished.

    Usage:
    >>> with work_dir(path):
    ...   subprocess.call('git status')

    '''
    starting_directory = os.getcwd()
    try:
        os.chdir(path)
        yield
    finally:
        os.chdir(starting_directory)
def work_dir ( path ) : starting_directory = os . getcwd ( ) try : os . chdir ( path ) yield finally : os . chdir ( starting_directory )
Context menager for executing commands in some working directory.
    Returns to the previous wd when finished.

    Usage:
    >>> with work_dir(path):
    ...   subprocess.call('git status')