class Test:
    a = 1

def __init__(self):
    self.b = 2
test = Test()
a_string = 'b'
print(test.__dict__[a_string])
print(test.__class__.__dict__['a'])
how to access the class variable by string in Python?