python装饰器

python装饰器

定义python的带参装饰器和不带参装饰器的方法

\#coding=gbk
\#带参装饰器和不带参装饰器

\# 不带参装饰器


def cat(func):
    """"""
    print "this cat don't has flowers"
    def wrappe():
        func()
    return wrappe


def catFlower(name):
    print "this cat has  flowers " + name
    def getFunc(func):
        ''''''
        def wrappe():
            func()
        return wrappe
    return getFunc
\# @cat
@catFlower("red")
def display():
    print "hello everyone"

import time 
print time.ctime()

if __name__ == '__main__':
    display() 
展开阅读全文

没有更多推荐了,返回首页