Skip to content

Instantly share code, notes, and snippets.

@lene
Last active January 30, 2018 14:37
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 lene/4083c9d67f8aa06da09a759d759e04ed to your computer and use it in GitHub Desktop.
Save lene/4083c9d67f8aa06da09a759d759e04ed to your computer and use it in GitHub Desktop.
Python decorator (class method)
from functools import wraps
def method_decorator(method):
@wraps(method)
def method_wrapper(self, *args, **kwargs):
return do_stuff(method(self, *args, **kwargs))
return method_wrapper
class Example:
@method_decorator
def example_method(self):
return 2 # returns do_stuff(2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment