Skip to content

Instantly share code, notes, and snippets.

@GameXG
Created February 21, 2017 02:24
Show Gist options
  • Save GameXG/e7c4c73769277da768af02b9e0054d2c to your computer and use it in GitHub Desktop.
Save GameXG/e7c4c73769277da768af02b9e0054d2c to your computer and use it in GitHub Desktop.
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