Skip to content

Instantly share code, notes, and snippets.

@hjhjw1991
Created April 14, 2017 04:11
Show Gist options
  • Save hjhjw1991/90e54765798895c545a52eeb1be509d7 to your computer and use it in GitHub Desktop.
Save hjhjw1991/90e54765798895c545a52eeb1be509d7 to your computer and use it in GitHub Desktop.
execute any method at a specific directory
def execAt(targetdir):
"""
execute the decorated method at specified directory
"""
def wrapper(method):
import os
def func(*args, **kvargs):
old = os.getcwd()
os.chdir(os.path.abspath(targetdir))
ret = method(*args, **kvargs)
os.chdir(old)
return ret
return func
return wrapper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment