Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Abdelkrim/1e05e575791875c06ae2983c672f5714 to your computer and use it in GitHub Desktop.
Save Abdelkrim/1e05e575791875c06ae2983c672f5714 to your computer and use it in GitHub Desktop.
debug methods like you would do it using Aspect Oriented Programming (AOP)
# 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