HI,
Here is my code which I am trying to run:
import array
a = []
for i in range(0,10):
a.append(i+2)
class A:
def __init__(self,a):
self.var1=a[0]
self.var2=a[1]
class B:
def __init__(self, a):
self.g1 = a[2]
self.arr = []
cl1 = []
var = A(a)
for j in range (0,10):
cl1.append(var)
print(cl1[9].var2)
cl2 = []
var3 = B(a)
#var3.arrayCreate(cl1)
for f in range(0,3):
cl2.append(var3)
print(cl2[0].arr[0].var1)
Basically what I am trying to do is: I have class A an array of which is a member of class B. Now I also want to have an array of class B and print out the class A member as I tried in the last line. It doesnt seem to print it and I get an error:
Traceback (most recent call last):
File "C:\Mine\python\arrays.py", line 33, in <module>
print(cl2[0].arr[0].var1)
IndexError: list index out of range