title: Python - Call a function of an object which is stored in a dict
body: <p>I have an Class which creates objects that contain a dict of functions. These functions are defined in the class.</p>
  
  <pre><code>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'
  </code></pre>
  
  <p>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.</p>
  
  <pre><code>from foo import Foo
  
  myFunctions = Foo.('a name', {0 : Foo.myFunction1, 1 : Foo.myFunction2})
  
  myFunctions.functions[0]()
  </code></pre>
  
  <p>I have this error :
  TypeError: unbound method myFunction1() must be called with Foo instance as first argument.</p>
  
  <p>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 :</p>
  
  <pre><code>myFunctions.myFunctions.functions[0]()
  </code></pre>
  
  <p>How can I call a function of this class which is stored in a dict attribute ?</p>