顯示具有 decorator 標籤的文章。 顯示所有文章
顯示具有 decorator 標籤的文章。 顯示所有文章

2011/09/21

Python Decorator (裝飾)

參考資料

Example 1
在原始function的return值做裝飾
def D1(fn):
    def newFn():
        return "" + fn() + ""
    return newFn

@D1
def f1():
    return "a sentence"

print f1()