title: Module imports and __init__.py
body: <p>I am trying to understand what the best practices are with regards to Python's (v2.7) import mechanics. I have a project that has started to grow a bit and lets say my code is organized as follows:</p>
  <pre><code>foo/
      __init__.py
      Foo.py
      module1.py
      module2.py
      module3.py
  </code></pre>
  <p>The package name is <code>foo</code> and underneath it I have module <code>Foo.py</code> which contains code for the class <code>Foo</code>. Hence I am using the same name for the package, module and class which might not be very clever to start with.</p>
  <p><code>__init__.py</code> is empty and class <code>Foo</code> needs to import <code>module1, module2 and module3</code> hence part of my <code>Foo.py</code> file looks like:</p>
  <pre><code># foo/Foo.py
  
  import module1
  import module2
  import module3
  
  class Foo(object):
      def __init__(self):
  ....
  ....
  if __name__ == '__main__':
      foo_obj = Foo()
  </code></pre>
  <p>However I later revisited this and I thought it would be better to have all imports in the <code>__init__.py</code> file. Hence my <code>__init__.py</code> now looks like:</p>
  <pre><code># foo/__init__.py
  
  import Foo
  import module1
  import module2
  import module3
  ....
  ....
      
  </code></pre>
  <p>and my <code>Foo.py</code> only needs to import <code>foo</code>:</p>
  <pre><code># foo/Foo.py
  
  import foo
  </code></pre>
  <p>While this looks convenient since it is a one liner, I am a bit worried that it might be creating circular imports. What I mean is that when the script <code>Foo.py</code> is run it will import everything it can and then <code>__init__.py</code> will be called which will import <code>Foo.py</code> again (is that correct?). Additionally using the same name for package, module and class makes things more confusing.</p>
  <p>Does it make sense the way I have done it? Or am I asking for trouble?</p>