"@"装饰器(在Python中) [英] "@" Decorator (in Python)
本文介绍了"@"装饰器(在Python中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
了解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?
此外,在方法前使用@previousMethod.setter
时setter
会做什么?谢谢.
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)
就是这样.
如您所见,装饰器被调用,所以它绝不是注释.
As you see, the decorator gets called, so it's by no means a comment.
这篇关于"@"装饰器(在Python中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文