Created
February 21, 2017 02:24
-
-
Save GameXG/e7c4c73769277da768af02b9e0054d2c to your computer and use it in GitHub Desktop.
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 logged(func): | |
@wraps(func) # 复制原始函数的名称、文档等内容到新函数。 | |
def with_logging(*args, **kwargs): | |
print (func.__name__ + " was called") | |
return func(*args, **kwargs) | |
return with_logging | |
@logged | |
def f(x): | |
"""does some math""" | |
return x + x * x | |
f(1) | |
print (f.__name__ ) # prints 'f' | |
print (f.__doc__) # prints 'does some math' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment