Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
可能的重复: 理解 Python 装饰器
“类装饰器”/“方法装饰器”(@)有什么作用?换句话说,这和普通评论有什么区别?
@
另外,在方法之前setter使用时会做什么@previousMethod.setter?谢谢你。
setter
@previousMethod.setter
@decorator def function(args): #body
只是语法糖:
def function(args): #body function = decorator(function)
就是这样。
如您所见,装饰器被调用,所以它绝不是评论。