title: Dynamic instantiation from string name of a class in dynamically imported module?
body: <p>In python, I have to instantiate certain class, knowing its name in a string, but this class 'lives' in a dynamically imported module. An example follows:</p>
  
  <p>loader-class script:</p>
  
  <pre><code>import sys
  class loader:
    def __init__(self, module_name, class_name): # both args are strings
      try:
        __import__(module_name)
        modul = sys.modules[module_name]
        instance = modul.class_name() # obviously this doesn't works, here is my main problem!
      except ImportError:
         # manage import error
  </code></pre>
  
  <p>some-dynamically-loaded-module script:</p>
  
  <pre><code>class myName:
    # etc...
  </code></pre>
  
  <p>I use this arrangement to make any dynamically-loaded-module to be used by the loader-class following certain predefined behaviours in the dyn-loaded-modules...</p>