Last active
January 29, 2020 00:16
-
-
Save Abdelkrim/1e05e575791875c06ae2983c672f5714 to your computer and use it in GitHub Desktop.
debug methods like you would do it using Aspect Oriented Programming (AOP)
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
# python 3 | |
def enter_exit_info(func): | |
def wrapper(*arg, **kw): | |
print(f'-- entering {func.__name__}') | |
res = func(*arg, **kw) | |
print(f'-- exiting {func.__name__}') | |
return res | |
return wrapper | |
@enter_exit_info | |
def f(x): | |
print(f'In: {x}') | |
res = x + 2 | |
print(f'Out: {res}') | |
return res | |
a = f(2) | |
# Outputs: | |
# -- entering f | |
# In: 2 | |
# Out: 4 | |
# -- exiting f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment