title: python string to function: globals() vs sys.module vs dictionary
body: <p>I want to know what is the best way to map the string to a function.
  so far I know I can use:</p>
  
  <ol>
  <li>globals()[func_string]</li>
  <li>sys.modules[__name__]</li>
  <li>funcs_dictionary["func_string" : func]</li>
  </ol>
  
  <p>Here is the code:</p>
  
  <pre><code>    &gt;&gt;&gt; def foo(arg):
      ...     print "I'm foo: %s" % arg
      ... 
      &gt;&gt;&gt; def bar(arg):
      ...     print "I'm bar: %s" % arg
      ... 
      &gt;&gt;&gt; 
      &gt;&gt;&gt; foo
      &lt;function foo at 0xb742c7d4&gt;
      &gt;&gt;&gt; bar
      &lt;function bar at 0xb742c80c&gt;
      &gt;&gt;&gt; 
  </code></pre>
  
  <p>globals()[func_string]:</p>
  
  <pre><code>    &gt;&gt;&gt; def exec_funcs_globals(funcs_string):
      ...     for func_string in funcs_string:
      ...         func = globals()[func_string]
      ...         func("from globals() %s" % func)
      ... 
      &gt;&gt;&gt; exec_funcs_globals(["foo", "bar"])
      I'm foo: from globals() &lt;function foo at 0xb742c7d4&gt;
      I'm bar: from globals() &lt;function bar at 0xb742c80c&gt;
      &gt;&gt;&gt; 
  </code></pre>
  
  <p>sys.modules[__name__]:</p>
  
  <pre><code>    &gt;&gt;&gt; import sys
      &gt;&gt;&gt; 
      &gt;&gt;&gt; def exec_funcs_thismodule(funcs_string):
      ...     thismodule = sys.modules[__name__]
      ...     for func_string in funcs_string:
      ...         func = getattr(thismodule, func_string)
      ...         func("from thismodule %s" % func)
      ... 
      &gt;&gt;&gt; exec_funcs_thismodule(["foo", "bar"])
      I'm foo: from thismodule &lt;function foo at 0xb742c7d4&gt;
      I'm bar: from thismodule &lt;function bar at 0xb742c80c&gt;
      &gt;&gt;&gt; 
  </code></pre>
  
  <p>funcs_dictionary["func_string" : func]:</p>
  
  <pre><code>    &gt;&gt;&gt; funcs = {
      ...     "foo" : foo,
      ...     "bar" : bar
      ... }
      &gt;&gt;&gt; 
      &gt;&gt;&gt; def exec_funcs_dict(funcs_string):
      ...     for func_string in funcs_string:
      ...         func = funcs[func_string]
      ...         func("from thismodule %s" % func)
      ... 
      &gt;&gt;&gt; exec_funcs_dict(["foo", "bar"])
      I'm foo: from thismodule &lt;function foo at 0xb742c7d4&gt;
      I'm bar: from thismodule &lt;function bar at 0xb742c80c&gt;
  </code></pre>
  
  <p>Originally I was worry about the sys.modules[__name__] will reload the modules and hurt the performance. But the code above seem to show that the function pointers are the same, so I guess I don't have to worry about it?</p>
  
  <p>What is the best use case for the option 1, 2, 3?</p>