在函数中使用self时接收到错误,该函数具有来自另一个s的另一个self

2024-04-25 22:01:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我想使用self.value的值,这是我在“func1”的函数内部的函数“take”中初始化的。但是,我在尝试这样做时收到了一个错误

代码:

class all():
    def __init__(self):
        self.temp = self.value # Here I declare it first before the self.new but still get error. May I know why?
        if:
            **func**
        else:
            **func**
        self.new = self.func1()

    def func1(self):
        **func**
        return ["{}".format(self.temp)]

    def take(value):
#In this example, the value already contained some values. and already been called. but in another program not in the same program.
        self.value = value

错误:

AttributeError: "all" object has no attribute "value"

Tags: the函数inselfnewvaluedef错误