Last active
December 17, 2021 01:34
-
-
Save neoneo40/3a280a28a28350c92fa8df64d8aacd08 to your computer and use it in GitHub Desktop.
decorator print function name in python. be useful with logger. http://stackoverflow.com/questions/251464/how-to-get-a-function-name-as-a-string-in-python. http://stackoverflow.com/questions/6200270/decorator-to-print-function-call-details-parameters-names-and-effective-values
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
def dump_func_name(func): | |
def echo_func(*func_args, **func_kwargs): | |
print('') | |
print('Start func: {}'.format(func.__name__)) | |
return func(*func_args, **func_kwargs) | |
return echo_func | |
class ClassName(object): | |
@dump_func_name | |
def add(self, a, b): | |
return a + b | |
c = ClassName() | |
c.add(3, 5) | |
# add | |
# 8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Might want to consider functools.wraps