Skip to content

Instantly share code, notes, and snippets.

@xire-
Created June 28, 2016 10:17
Show Gist options
  • Save xire-/d3bbced90a6f20761bf2459eda6a7cb4 to your computer and use it in GitHub Desktop.
Save xire-/d3bbced90a6f20761bf2459eda6a7cb4 to your computer and use it in GitHub Desktop.
template of a parametric decorator
from functools import wraps
class print_in_out:
def __init__(self, in_str, out_str):
self.in_str = in_str
self.out_str = out_str
def __call__(self, f):
@wraps(f)
def wrapped(*args, **kargs):
print('inn: {}'.format(self.in_str))
ris = f(*args, **kargs)
print('out: {}'.format(self.out_str))
return ris
return wrapped
@print_in_out("hello", "world")
def sayHello(a1, a2, a3, a4):
print('sayHello arguments:', a1, a2, a3, a4)
return 'lol'
ris = sayHello("say", "hello", "argument", "list")
print(ris)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment