title: Instantiating a python class from a module by full name
body: <p>I have a need to create an instance of a python class and store it in a C# variable. The input data for the process is a full module name and a class name. I am trying to use the following approach:</p>
  
  <pre class="lang-cs prettyprint-override"><code>// Here's a sample input:
  var moduleName = "sp.content.abilities.torpedo"
  var className = "AbilityTorpedo"
  
  // Here's my module loading and class instaitiation
  var moduleScope = ScriptEngine.ImportModule(moduleName);
  var scriptClass = moduleScope.GetVariable(className);
  return ScriptEngine.Operations.CreateInstance(scriptClass);
  </code></pre>
  
  <p>My folder structure looks like this and the "Scripts" directory is added as one of the IronPython's search paths (the <code>torpedo.py</code> does indeed contain the <code>AbilityTorpedo</code> class):</p>
  
  <pre><code>Scripts
  │   .editorconfig
  │   __main__.py
  │                                       
  └───sp                                                               
      │   __init__.py                                              
      │                                         
      └───content                                                                    
          │   __init__.py               
          │                                     
          └───abilities                         
                  torpedo.py                    
                  __init__.py
  
  </code></pre>
  
  <p>When running the listed instantiation method, the <code>moduleScope.GetVariable(className);</code> line fails with the following exception:</p>
  
  <pre><code>'ObjectDictionaryExpando' object has no attribute 'AbilityTorpedo'
  </code></pre>
  
  <p>When debugging, I've noticed that the ImportModule operation returned the module loaded from the first part of the name, while also loading the entirety of the module hierarchy (for example, the <code>content</code> module marked in red)<a href="https://i.stack.imgur.com/b7s5S.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/b7s5S.png" alt="moduleScope contents from debug"></a></p>
  
  <p>Is there a proper way for me to load the module by it's full name instead of traversing down the scope to find the class I need?</p>