title: Calling a function from string inside the same module in Python?
body: <p>Lets say I have a function <code>bar</code> inside a module called <code>foo.py</code> . Somewhere inside foo.py, I want to be able to call bar() from the string "bar". How do I do that?</p>
  
  <pre><code># filename: foo.py
  import sys
  
  def bar():
    print 'Hello, called bar()!'
  
  if __name__ == '__main__':
    funcname = 'bar'
    # Here I should be able to call bar() from funcname
  </code></pre>
  
  <p>I know that there exists some built-in function in python called 'getattr'. However, it requires 'module object' to be the first parameter. How to obtain the 'module object' of the current module?</p>