title: import * from module named as a variable
body: <p>I've got a situation where I need to <code>import *</code> from a list of modules which may or may not exist.  So far, I've got a working solution that goes a little something like this:</p>
  
  <pre><code>for module in modules:
      try:
          imported = __import__(module, globals(), locals(), [], -1)
          for sub in module.split(".")[1:]:
              imported = getattr(imported, sub)
          for name in  [n for n in dir(imported) if not n.startswith("_")]:
              globals()[name] = getattr(imported, name)
      except (ImportError, AttributeError):
          pass
  </code></pre>
  
  <p>This works, but is a total mess and confuses linters no end when they're looking for the variables that get imported in this way.  I'm certain I'm missing something in the way <code>__import__</code> works, since surely <code>from foo import *</code> doesn't generate such a horrible call as I've got above.  Can anyone enlighten me?</p>
  
  <p><strong>Update:</strong></p>
  
  <p>The actual use case here is refactoring a django project settings file, to move app-specific settings into a settings file within that app.  Currently, all settings are in the main settings file, which has become unmaintainably large.  I need to retain the ability to override any of the settings defined in that way from another settings file (<code>client_settings.py</code>), which gets imported as <code>from foo_project.client_settings import *</code> at the bottom of the settings file.</p>
  
  <p>Doing <code>from app.settings import *</code> for each app would work, but I want to drive this from the installed apps setting to maintain DRY.</p>