标签:div code http not pre 日志 The htm run
def a_decorator(func): def wrapTheFunc(): print "before decorator" func() print "end decorator" return wrapTheFunc @a_decorator def a_func_need_decorator(): print "In a_func_need_decorator()" a_func_need_decorator()
输出
before decorator In a_func_need_decorator() end decorator
不是很明白?
@a_decorator
def a_func_need_decorator():
等价于
a_func_need_decorator = a_decorator(a_func_need_decorator)
修改下代码
def a_decorator(func): def wrapTheFunc(): print "before decorator" func() print "end decorator" return wrapTheFunc def a_func_need_decorator(): print "In a_func_need_decorator()" a_func_need_decorator = a_decorator(a_func_need_decorator) a_func_need_decorator()
结果是一致的
是的,举例
def test(a): print a test2 = test test2("hello")
输出
hello
账号验证
日志
https://www.runoob.com/w3cnote/python-func-decorators.html
标签:div code http not pre 日志 The htm run
原文地址:https://www.cnblogs.com/kaituorensheng/p/11235219.html