I have defined an object, and I would like to be able to call attributes of that object in a loop but I am not sure how to do this. This is the (wrong) example code I wrote to try to indicate what I would like to do:
class my_data:
def __init__(self,a,b,c,d):
self.a = 'e'
self.b = 'f'
self.c = 'g'
self.d = 'h'
test=my_data('a','b','c','d')
#print(test.a)
#e
index=['a','b','c','d']
#what I want:
my_var = test.index[2]
#where index[2] is equivalent to c and thus my_var is 'g'
the error I get is:
AttributeError: 'my_data' object has no attribute 'index'
Which I understand, because it is looking for the specific attribute index and not the value of the array index[2], but I cannot figure out how to get around this. I need it because I want to use this in a loop.
Thanks!