Skip to content

Instantly share code, notes, and snippets.

@nenetto
Created September 26, 2023 10:14
Show Gist options
  • Save nenetto/b052c76bf8245cad4e45bfe5f2ecb9c9 to your computer and use it in GitHub Desktop.
Save nenetto/b052c76bf8245cad4e45bfe5f2ecb9c9 to your computer and use it in GitHub Desktop.
Decorator using wrapper
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