title: Circular & nested imports in python
body: <p>I'm having some real headaches right now trying to figure out how to import stuff properly.  I had my application structured like so:</p>
  
  <pre><code>main.py
  util_functions.py
  widgets/
   - __init__.py
   - chooser.py
   - controller.py
  </code></pre>
  
  <p>I would always run my applications from the root directory, so most of my imports would be something like this</p>
  
  <pre><code>from util_functions import *
  from widgets.chooser import *
  from widgets.controller import *
  # ...
  </code></pre>
  
  <p>And my <code>widgets/__init__.py</code> was setup like this:</p>
  
  <pre><code>from widgets.chooser import Chooser
  from widgets.controller import MainPanel, Switch, Lever
  
  __all__ = [
    'Chooser', 'MainPanel', 'Switch', 'Lever',
  ]
  </code></pre>
  
  <p>It was working all fine, except that <code>widgets/controller.py</code> was getting kind of lengthy, and I wanted it to split it up into multiple files:</p>
  
  <pre><code>main.py
  util_functions.py
  widgets/
   - __init__.py
   - chooser.py
   - controller/
      - __init__.py
      - mainpanel.py
      - switch.py
      - lever.py
  </code></pre>
  
  <p>One of issues is that the <code>Switch</code> and <code>Lever</code> classes have static members where each class needs to access the other one.  Using imports with the <code>from ___ import ___</code> syntax that created circular imports.  So when I tried to run my re-factored application, everything broke at the imports.</p>
  
  <p>My question is this:  How can I fix my imports so I can have this nice project structure?  I cannot remove the static dependencies of <code>Switch</code> and <code>Lever</code> on each other. </p>