Created
April 14, 2017 04:11
-
-
Save hjhjw1991/90e54765798895c545a52eeb1be509d7 to your computer and use it in GitHub Desktop.
execute any method at a specific directory
This file contains hidden or 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
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