Python类(';';对象没有属性';';)
我定义了一个类,但是当我想在类中使用函数时,它会给我一个错误,如下所示。有人能帮我吗?非常感谢你Python类(';';对象没有属性';';),python,Python,我定义了一个类,但是当我想在类中使用函数时,它会给我一个错误,如下所示。有人能帮我吗?非常感谢你 points = 5 class State: def __init__(self, a, b, E_min, E_max, P_s_a, P_s_b, points)): self.state = state self.isEnd = False self.a = a self.b = b self.E_mi
points = 5
class State:
def __init__(self, a, b, E_min, E_max, P_s_a, P_s_b, points)):
self.state = state
self.isEnd = False
self.a = a
self.b = b
self.E_min = E_min
self.E_max = E_max
self.P_s_a = P_s_a
self.P_s_b = P_s_b
self.points = points
y_model = np.zeros(self.points)
def model(self):
for j in range(0, points):
y_model[j] = a * j + b
print(State.model(2,3))
AttributeError: class State has no attribute 'model'
当您定义
模型时,它是在\uuuu init\uuuu
中定义的。要解决此问题,必须更改缩进
points = 5
class State:
def __init__(self, a, b, E_min, E_max, P_s_a, P_s_b, points)):
self.state = state
self.isEnd = False
self.a = a
self.b = b
self.E_min = E_min
self.E_max = E_max
self.P_s_a = P_s_a
self.P_s_b = P_s_b
self.points = points
y_model = np.zeros(self.points)
def model(self):
for j in range(0, points):
y_model[j] = a * j + b
print(State.model(2,3))
缩进错误,model()
定义是\uuuuu init\uuuuu()
的内部定义。请提供完整的错误消息以及一个。