Python - 类构造函数中装饰方法的问题

时间:2021-07-30 22:53:52

标签: python python-decorators class-method

假设有人用一个方法构造了一个简单的类:

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

显然这行不通,因为 selfargument 作为元组返回。这意味着 argument 中将缺少 method1

装饰函数有没有办法将多个参数传递给它的装饰器?我是这个概念的新手,需要我正在创建的包的答案。

0 个答案:

没有答案