Discuss / Python / 代码

代码

Topic source

gannyee

#1 Created at ... [Delete] [Delete and Lock User]
 def log(func):
...     @functools.wraps(func)
...     def wrapper(*args,**kw):
...         print('begin call %s():' %func.__name__)
...         function = func(*args,**kw)
...         print('end call %s():' %func.__name__)
...         return function
...     return wrapper
...


>>> @log
... def now():
...     print('2015-09-16')
...
>>> now()
begin call now():
2015-09-16
end call now():

  • 1

Reply