title: Python callbacks into the main module (functions and variables)
body: <p>I am trying to have a module that provides a framework of sorts to short declarative one-file scripts that I write.  In the short scripts, I would like to define a number of variables and functions that are accessed or called back by the framework module.</p>
  
  <p>I am stuck ... I have tried two approaches, and I am not crazy about either one.  Is there a better way?</p>
  
  <p><strong>First approach:</strong></p>
  
  <p>Framework module:</p>
  
  <pre><code>import __main__
  def test():
      print __main__.var
      print __main__.func()
  </code></pre>
  
  <p>Script:</p>
  
  <pre><code>import framework
  var="variable"
  def func():
      print "function"
  framework.test()
  </code></pre>
  
  <p>I like this approach and it works, but eclipse gives me an 'Undefined variable from import: var' error on any imported variable or function from main.  Obviously, this is not correct as it works, but it clutters up eclipse with many false errors.</p>
  
  <p><strong>Second Approach:</strong></p>
  
  <p>Framework module:</p>
  
  <pre><code>def test(glob):
      print glob['var']
      print glob['func']()
  </code></pre>
  
  <p>Script:</p>
  
  <pre><code>import framework
  var="variable"
  def func():
      print "function"
  framework.test(globals())
  </code></pre>
  
  <p>This seems to work and does not give me errors, but I don't like the dictionary type notation used to call variables and functions ... especially for functions: func'funcName'.</p>
  
  <p>Is there a better way to implement this that results in clean code?  Can I pass in a module name (ie <strong>main</strong>) as an argument to a function?  Can Eclipse errors on <strong>main</strong> for the first approach be turned off?</p>