I would like to be able to select the class' property by it's name. This is my code:
class example(object):
def __init__(self):
self.one = "1"
self.two = "2"
x = example()
list = ["one", "two"]
# I want to get x.one here by referring to it by list[0]
How can I do this?
Worked example:
class example(object):
def __init__(self):
self.one = "one"
self.two = "two"
def test(self):
list = ["one", "two"]
print(getattr(self, list[1]))
x = example()
x.test()