Skip to content

Instantly share code, notes, and snippets.

@momijiame
Created June 9, 2020 10:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save momijiame/c8542f4b174af1716a6737834f9ca78f to your computer and use it in GitHub Desktop.
Save momijiame/c8542f4b174af1716a6737834f9ca78f to your computer and use it in GitHub Desktop.
>>> 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment