cornsea

python的decorator

下面这段小代码,展示了decorator的基本功能,详细的讲解google:python decorator...

 

def abc(fun):
    def myfun():
        print "abc"
        fun()
    return myfun

@abc
def test():
    print "test"

print test
test()
我这里的输出是:

<function myfun at 0xb7598a74>
abc
test

:)

posted on 2010-11-23 22:55  cornsea  阅读(185)  评论(0编辑  收藏  举报

导航