Created
July 22, 2012 19:22
-
-
Save orip/3160773 to your computer and use it in GitHub Desktop.
temp_chdir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os, contextlib | |
@contextlib.contextmanager | |
def temp_chdir(path): | |
""" | |
Usage: | |
>>> with temp_chdir(gitrepo_path): | |
... subprocess.call('git status') | |
""" | |
starting_directory = os.getcwd() | |
try: | |
os.chdir(path) | |
yield | |
finally: | |
os.chdir(starting_directory) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey, I want to use this code in an Apache 2.0 licensed project, can I do so with your permission?