title: Set a variable before importing module __init.py__
body: <p>My Python application structure is thus:</p>
  
  <pre><code>run.py
  app/__init.py__
  app/config.py
  app/&lt;other modules in app&gt;
  </code></pre>
  
  <p>In my <code>app/__init.py</code>, I'd like to check a variable <code>DEBUG_MODE</code> and depending on its value, start a python <code>Logger</code> if <code>DEBUG_MODE == False</code>, and simply print to console if it is <code>True</code>. My currently attempted (and not working) solution is to have three files:</p>
  
  <p>app/config.py</p>
  
  <pre><code>DEBUG_MODE = False
  </code></pre>
  
  <p>app/__init__.py</p>
  
  <pre><code>app = MyApp()
  from config import DEBUG_MODE
  app.debug = DEBUG_MODE
  if not app.debug:
      import logging
      ...
  </code></pre>
  
  <p>run.py</p>
  
  <pre><code>from app import config
  config.DEBUG_MODE = True
  from app import app
  </code></pre>
  
  <p>The problem, of course, is that by the time my code reaches <code>config.DEBUG_MODE=True</code>, the <code>app</code> module's init code has already been called because my config file is part of the app module.</p>
  
  <p>How can I tell the module that I want to enable debugging <em>at run time</em> from my run.py script?</p>