Created
June 28, 2016 10:17
-
-
Save xire-/d3bbced90a6f20761bf2459eda6a7cb4 to your computer and use it in GitHub Desktop.
template of a parametric decorator
This file contains 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
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