Skip to content

Instantly share code, notes, and snippets.

@Newky
Created March 13, 2013 12:30
Show Gist options
  • Save Newky/5151640 to your computer and use it in GitHub Desktop.
Save Newky/5151640 to your computer and use it in GitHub Desktop.
restoring cwd with a decorator.
def restore_cwd(func):
"""
decorator to restore the current working directory
"""
def wrapper(*args, **kwargs):
cwd = os.getcwd()
results = func(*args, **kwargs)
os.chdir(cwd)
return results
return wrapper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment