Skip to content

Instantly share code, notes, and snippets.

@AlexKay28
Last active October 2, 2021 18:10
Show Gist options
  • Save AlexKay28/163f8cd6da7268a4b6dfd9aa8aeeceaa to your computer and use it in GitHub Desktop.
Save AlexKay28/163f8cd6da7268a4b6dfd9aa8aeeceaa to your computer and use it in GitHub Desktop.
Get in-out wrapper for function
import os
def getInOut(orig_fun=None, path_in=None, path_out=None):
def _decorate(fun):
@functools.wraps(fun)
def wrapper(*args, **kwargs):
os.chdir(path_in)
fun(*args, **kwargs)
os.chdir(path_out)
if orig_fun:
return _decorate(orig_fun)
else:
return _decorate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment