2012-04-17 117 views
-4

可能重複:
Understanding Python decorators「@」 裝飾(在Python)

什麼功能的 「類裝飾」/ 「法裝飾」(@)服務?換句話說,這和普通評論有什麼區別?

另外,在方法之前使用@previousMethod.setter之前,setter會做什麼?謝謝。

+1

裝修工不是一個評論。檢查[文檔](http://docs.python.org/reference/compound_stmts.html#function)是什麼。至於後面的說明,它使用[''property()''](http://docs.python.org/library/functions.html#property)來避免getters/setter支持屬性。 – 2012-04-17 12:50:08

+0

http://stackoverflow.com/questions/739654/understanding-python-decorators – tMC 2012-04-17 13:40:30

回答

3
@decorator 
def function(args): 
    #body 

是隻是語法糖:

def function(args): 
    #body 

function = decorator(function) 

這是真的了。

正如你所看到的,裝飾器被調用,所以它絕不是一個評論。