python get attribute by name code example
Example 1: python class get attribute by name
>>> class c:
pass
o = c()
>>> setattr(o, "foo", "bar")
>>> o.foo
'bar'
>>> getattr(o, "foo")
'bar'
Example 2: python get object attribute by string
x = getattr(t, 'attr1')
setattr(t, 'attr1', 21)