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'
asked Mar 6, 2020 at 1:49
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))
answered Mar 6, 2020 at 1:53
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.