title: Python : How to call a global function from a imported module
body: <p>Would it be possible to call a global function from imported function in Python 3?</p>
  
  <p>./folders/folder1/def.py</p>
  
  <pre><code>def do_test():
    print("++ def.do_test()")
    global_function_1()
    print("-- def.do_test()")
  </code></pre>
  
  <p>./main.py</p>
  
  <pre><code>import importlib
  
  def global_function_1():
    print("doing function 1 thing...")
  
  mod = importlib.import_module('folders.folder1.def')
  mod.do_test()
  </code></pre>
  
  <p>I have the error like this.</p>
  
  <pre><code>++ def.do_test()
  Traceback (most recent call last):
    File "C:\src\python\class2\main.py", line 10, in &lt;module&gt;
      mod.do_test()
    File "C:\src\python\class2\folders\folder1\def.py", line 4, in do_test
      global_function_1()
  NameError: name 'global_function_1' is not defined
  </code></pre>
  
  <p>Apparently, the same functions works just fine if defined in the same file.</p>
  
  <pre><code>def global_function_1():
    print("calling the global function 1")
  
  
  def do_test():
    print("++ def.do_test()")
    global_function_1()
    print("-- def.do_test()")
  
  do_test()
  </code></pre>
  
  <p>The results is</p>
  
  <pre><code>++ def.do_test()
  calling the global function 1
  -- def.do_test()
  </code></pre>
  
  <p>If Python doesn't allow this, what would be the closest alternative ?
  In my real project, the global functions has number of accesses to the global
  variables. If all the possible, I'd like to avoid putting all the global functions
  and variables in a separate class.</p>
  
  <p>EDIT : The above is the code excerpt to highlight my problem. In my real project, </p>
  
  <ol>
  <li>I have dozen of global functions. So, passing its pointer through function parameter is not preffered.</li>
  <li>I have dozen of other def.py files in multiple folders. I need to pick up the def.py file at run-time depending on variety conditions. So, static reference from main.py to def.py is not preffered.</li>
  </ol>