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()
输出html
before decorator In a_func_need_decorator() end decorator
不是很明白? python
@a_decorator bash
def a_func_need_decorator():函数
等价于spa
a_func_need_decorator = a_decorator(a_func_need_decorator)日志
修改下代码code
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()
结果是一致的htm
是的,举例对象
def test(a): print a test2 = test test2("hello")
输出blog
hello
帐号验证
日志