I have an Class which creates objects that contain a dict of functions. These functions are defined in the class.
class Foo:
def __init__(self, name, functions):
self.name = name
self.functions = functions
def myFunction1(self):
print self.name
return 'foo'
def myFunction2(self):
return 'bar'
In another file, I instance an object of the previous class and I want to run one of the functions that is in the dict.
from foo import Foo
myFunctions = Foo.('a name', {0 : Foo.myFunction1, 1 : Foo.myFunction2})
myFunctions.functions[0]()
I have this error : TypeError: unbound method myFunction1() must be called with Foo instance as first argument.
I understand that when I execute the last line, I just call the function without call it with an object of Foo as first argument. But I can not write this :
myFunctions.myFunctions.functions[0]()
How can I call a function of this class which is stored in a dict attribute ?