How do I get the attribute value of an object when I have a string of the attribute name that I want? For example, suppose cmd_i
has attributes q0
and q1
. I'd like to be able to do this:
for x in range(2):
print('cmd_i.q{}'.format(x))
Instead of having to do this:
print(cmd_i.q0)
print(cmd_i.q1)