Created
November 25, 2015 07:15
-
-
Save dmitryhd/ed4de21a496c5747ff9d to your computer and use it in GitHub Desktop.
Python decorator with params
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 decor(func): | |
| def wrap(*args, **kwargs): | |
| print('before a') | |
| print(args) | |
| args[0].log() | |
| res = func(*args, **kwargs) | |
| print('after a') | |
| return wrap | |
| def param_decor(param1): | |
| def decor(func): | |
| def wrap(*args, **kwargs): | |
| print('before a with ', param1) | |
| res = func(*args, **kwargs) | |
| print('after a') | |
| return res | |
| return wrap | |
| return decor | |
| @param_decor('testsststs') | |
| def a(arg1): | |
| print('a', arg1) | |
| class A: | |
| @decor | |
| def meth1(self): | |
| print('mehod1') | |
| def log(self): | |
| print('log1') | |
| a('argsss') | |
| #A().meth1() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment