我想使用在函数“ func1”内的函数“ take”中启动的self.value的值。但是,尝试这样做时出现错误。
代码:
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"
答案 0 :(得分:1)
发生此错误的原因是,您未在构造方法( init )方法中定义值。
def __init__(self):
self.value = 20(example purpose)