Skip to content

Instantly share code, notes, and snippets.

@rec
Created July 12, 2020 09:44
Show Gist options
  • Save rec/914796ed4bb8c1bff1f7e1d8fa1e0ead to your computer and use it in GitHub Desktop.
Save rec/914796ed4bb8c1bff1f7e1d8fa1e0ead to your computer and use it in GitHub Desktop.
# Version 3
def print_before2(label):
def decorator(func):
@functools.wraps(func)
def wrapped(*args, **kwds):
print(label, func.__name__, args, kwds)
return func(*args, **kwds)
return wrapped
return decorator
@print_before2('DEBUG:')
def important(lives, money, valuables=None):
pass
# Test at the command line:
>>> important(23, 105.17, valuables=['dogs'])
DEBUG: important (23, 105.17) {'valuables': ['dogs']}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment