Last active
January 30, 2018 14:37
-
-
Save lene/4083c9d67f8aa06da09a759d759e04ed to your computer and use it in GitHub Desktop.
Python decorator (class method)
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
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