The code below
class attsClass():
def __init__(self,aw,ax,ay,az):
self.aw = aw
self.ax = ax
self.ay = ay
self.az = az
ac = attsClass('W','X','Y','Z')
ac.ax
here I will get the result which is 'X',but if i call like how i did below we get an error
att_names = ['aw','ax','ay','az']
for att in att_names:
print(ac.att)
here I can't access the attribute
only with this can I access it
att_names = ['ax','ay','az']
for att in att_names:
print(att, getattr(ac, att))
can someone explain why?