假设有人用一个方法构造了一个简单的类:
class Object:
def method1(self, argument):
self.attribute = argument
现在他/她定义了另一种方法,但由 method1
修饰:
class Object:
def method1(self, argument):
self.attribute = argument
@method1
def method2(self, argument):
return self, argument
显然这行不通,因为 self
和 argument
作为元组返回。这意味着 argument
中将缺少 method1
。
装饰函数有没有办法将多个参数传递给它的装饰器?我是这个概念的新手,需要我正在创建的包的答案。