title: Importing a fixed module from a dynamic path at runtime in python3
body: <p>I have searched around and not found a solution to this particular Python3 problem. Perhaps it's the keywords I'm using, or it could be just a special use case. In the event that my problem is the latter, here is my question:</p>
  
  <p>I'm developing a python (3) script which needs to use a python module which has been compiled locally in the user's home directory. I do not have anything so fancy as a configure script to configure this path for the user as an automated process. I want to pass the path to the python module to the script at runtime as a command line argument, and then dynamically load that module. For example, I will call:</p>
  
  <pre><code>$ myscript.py --modpath /home/user/path/to/ModuleSource
  </code></pre>
  
  <p>and then in my code call something like the following when I parse the command line arguments:</p>
  
  <pre><code>import sys
  sys.path.append(localModulePath)
  import GlobalModuleName
  </code></pre>
  
  <p>The problem is that in the static code for my script which uses the module methods, the actual module cannot be resolved until runtime when the definitions for the module are passed to my script.
  That is, if I have python code like the following</p>
  
  <pre><code>GlobalModuleName.moduleFunc()
  </code></pre>
  
  <p>I get runtime errors of "<em>NameError: name 'GlobalModuleName' is not defined</em>". </p>
  
  <p>How do I get this configuration to work without generating an error? I am certain that the code that will use the dynamic definitions of the module is correct. Thanks for the pointers in advance.</p>