0

I defined a class, but when I want to use the function in the class, it gives me an error as follows. Can anybody help me? thank you so much.

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' 
2
  • Your indentation is wrong, the model() definition is internal to __init__(). Commented Mar 6, 2020 at 1:51
  • Please provide the entire error message, as well as a minimal reproducible example. Commented Mar 6, 2020 at 2:59

1 Answer 1

1

When you define model, it is defined inside __init__. To fix this you must change the indentation.

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)) 
Sign up to request clarification or add additional context in comments.

Comments