标签:dem blog function tar 输出 功能 start ret 增强
【装饰器】
将方法和函数封装,使之可以对其他函数的功能进行增强。
#coding:utf8
def mydecorator(function):
def _mydecorator(*args,**kw):
#在调用实际函数之前的准备工作
print ‘start‘
res = function(*args,**kw)
#做完某项填充工作
print ‘end‘
return res
return _mydecorator
@mydecorator
def demo():
print ‘This is test‘
demo()
输出
start This is test end
标签:dem blog function tar 输出 功能 start ret 增强
原文地址:http://www.cnblogs.com/nerdlerss/p/7079920.html