"@" Decorator (in Python)

Possible Duplicate:
Understanding Python decorators

What function does the "class decorator"/"method decorator" ( @ ) serve? In other words, what is the difference between this and a normal comment?

Also, what does setter do when using @previousMethod.setter before a method? Thank you.


@decorator
def function(args):
    #body

is just syntactic sugar for:

def function(args):
    #body

function = decorator(function)

That's really it.

As you see, the decorator gets called, so it's by no means a comment.

链接地址: http://www.djcxy.com/p/23806.html

上一篇: 解释Python装饰器如何工作

下一篇: “@”装饰器(在Python中)