0

I want to write a general code that take the number of stages of a turbine and then calculate different features of every blade. I want to use class in this code but there is something wrong with my code and I simplified the problem in code below:

class aa():
    x1 =1
    y1=2
    z1=3
class bb():
    x2=aa()
    y2=aa()
class cc:
    x3=[]
    y3=[]

ee=cc()

for i in range(0, 3):
    ee.x3.append(bb())
    ee.y3.append(bb())
print(ee.x3[0])  # prints 12 !!

ee.x3[0].x2.x1=7
ee.y3[0].x2.x1=12
print(ee.x3[0].x2.x1)  # prints 12 instead of 7 !!

thanks

  • `print(ee.x3[0]) # prints 12 !!` no, it does not. But the problem is that you are using all class variables when you are supposed to be using instance variables. This is a *basic* part of writing Python class definitions. At the very least, read the [tutorial](https://docs.python.org/3/tutorial/classes.html) and don't assume things work like you imagine – juanpa.arrivillaga Dec 13 '20 at 20:20
  • yes. thanks for your help – Hosein Bashi Dec 13 '20 at 20:41

0 Answers0