In a program I have multiple instances of a particular class with a Func attribute as attributes within another class. The Func attribute is a string which is the name of a function in the parent class. The parent class has a function that I want to access a particular instance of the child class and execute the function associated with it, which updates a variable within the parent class.
I have tried the following (minimal example):
class a:
def __init__(self):
self.func = "bar"
class foo:
def __init__(self):
self.val = 0
self.e = a()
def bar(self):
self.val += 1
def baz(self):
a = getattr(globals()["foo"](), self.e.func)
a()
Creating an instance of foo and running foo.baz causes foo.val to remain at 0, which is not what I want to happen. How do I make it so that self.val is updated?