python装饰器的使用

python装饰器的使用

def ty(func):                           #定义装饰器
    def zty():
        print 'hehehe'                  #装饰内容  
        func()
        print ' '

    return zty


@ty
def fun1():
    print 'fun1'
@ty
def fun2():
    print 'fun2'
@ty
def fun3():
    print 'fun3'


fun1()

fun2()

fun3()
posted @ 2016-07-09 22:11  aallennty  阅读(74)  评论(0编辑  收藏  举报