2012-04-17 118 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) 

这是真的了。

正如你所看到的,装饰器被调用,所以它绝不是一个评论。