>>> def wrap(f):
... # NOTE: self は args[0] に入る
... def _wrap(*args, **kwargs):
... print('Before')
... res = f(*args, **kwargs)
... print('After')
... return res
... return _wrap
...
>>>
>>> class Example:
... @wrap
... def greet(self):
... print('Hello, World!')
...
>>> o = Example()
>>> o.greet()
Before
Hello, World!
After
Created
June 9, 2020 10:29
-
-
Save momijiame/c8542f4b174af1716a6737834f9ca78f to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment