title: Iterate the classes defined in a module imported dynamically
body: <p>I have a module from a child package that is imported dynamically; how can I iterate over the classes that it contains?</p>
  <p>I have been importing the module and listing the names like this:</p>
  <pre><code>package = current_module.__name__
  package = package[:package.rindex(&quot;.&quot;)] # get the package
  package = &quot;%s.sub.%s&quot;%(package,name) # make the name of the child
  print &quot;(loading package %s)&quot;%package
  module = __import__(package) # this succeeds
  for name,obj in inspect.getmembers(module):
      print name,type(obj)
  </code></pre>
  <p>This only prints module attributes and not the class types that the module defines:</p>
  <pre><code>__builtins__ &lt;type 'dict'&gt;
  __doc__ &lt;type 'NoneType'&gt;
  __file__ &lt;type 'str'&gt;
  __name__ &lt;type 'str'&gt;
  __package__ &lt;type 'NoneType'&gt;
  __path__ &lt;type 'list'&gt;
  imported_package &lt;type 'module'&gt;
  </code></pre>
  <hr />
  <p>It seems that my classes are not in the <code>__dict__</code> <strong>unless</strong> the <code>fromlist</code> is non-empty!  The values in the from-list don't seem to be validated though; <code>[&quot;&quot;]</code> seems to work just fine, and suddenly the classes show up!</p>
  <p>Can anyone explain why this is?</p>
  <p>(Standard ubuntu python 2.7.1+ (r271:86832)</p>