Last active
June 16, 2016 12:04
-
-
Save curtisforrester/3ee602a14bce2b3dc90604d20cfe6d3f to your computer and use it in GitHub Desktop.
Python decorator to print function arguments
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
from functools import wraps | |
def print_args(): | |
def decorator(func): | |
@wraps(func) | |
def func_wrapper(*args, **kwargs): | |
print('args: [%r], kwargs: [%r]' % (args, kwargs)) | |
return func(*args, **kwargs) | |
return func_wrapper | |
return decorator | |
@print_args() | |
def foo(parm1, parm2, parm3='third'): | |
pass | |
foo('first', parm2='second') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment