Here is my class implementation
class A:
def __init__(self,a,b):
self.result = None
self.a = a
self.b = b
self.add()
def add(self):
self.result = self.a+self.b
return
My class A has result as an attribute. I want to access the class attribute i.e; result by reading the result string from dictionary. Below is the implementation I tried.
x = 'result' # I will get from other source
obj = A(1,2)
obj.x # Here x = result and the result is the actual class attribute
Error:
AttributeError: A instance has no attribute 'x'
Could anyone tell me how to access the class attributes by converting the string to object?