title: Using a dictionary to select function to execute
body: <p>I am trying to use functional programming to create a dictionary containing a key and a function to execute:  </p>
  
  <pre><code>myDict={}
  myItems=("P1","P2","P3",...."Pn")
  def myMain(key):
      def ExecP1():
          pass
      def ExecP2():
          pass
      def ExecP3():
          pass
          ...
      def ExecPn():
          pass  
  </code></pre>
  
  <p>Now, I have seen a code used to find the defined functions in a module, and I need to do something like this:</p>
  
  <pre><code>    for myitem in myItems:
          myDict[myitem] = ??? #to dynamically find the corresponding function
  </code></pre>
  
  <p>So my question is, How do I make a list of all the <code>Exec</code> functions and then assign them to the desired item using the a dictionary? so at the end I will have <code>myDict["P1"]() #this will call ExecP1()</code></p>
  
  <p>My real problem is that I have tons of those items and I making a library that will handle them so the final user only needs to call <code>myMain("P1")</code></p>
  
  <p>I think using the inspect module, but I am not so sure how to do it.</p>
  
  <p>My reason to avoid:</p>
  
  <pre><code>def ExecPn():
      pass
  myDict["Pn"]=ExecPn
  </code></pre>
  
  <p>is that I have to protect code as I am using it to provide a scripting feature within my application.</p>