Created
September 26, 2023 10:14
-
-
Save nenetto/b052c76bf8245cad4e45bfe5f2ecb9c9 to your computer and use it in GitHub Desktop.
Decorator using wrapper
This file contains 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 trace_decorator(func): | |
@wraps(func) | |
def wrapper(*args, **kwargs): | |
# Decorate before | |
print('Hello') | |
# Call function | |
result = func(*args, **kwargs) | |
# Decorate after | |
print('Bye') | |
# Return | |
return result | |
return wrapper | |
# Use decorator as | |
@trace_decorator | |
def fibonacci(n): | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment