title: Python module layout where subdirectory name is the same as file
body: <p>I am used to a scripting language where it is very common to lay out modules like so:</p>
  
  <pre><code>lib/Foo.pm
  lib/Foo/Bar.pm
  lib/Foo/Baz.pm
  </code></pre>
  
  <p>Where you have Foo.pm, then there is a directory called Foo and underneath you place submodules.</p>
  
  <p>In Python, I tried to mimic the layout like so:</p>
  
  <pre><code>modules/foo.py
  modules/foo/bar.py
  modules/foo/baz.py
  </code></pre>
  
  <p>However, this wouldn't work because when I do:</p>
  
  <pre><code>from foo import Foo
  </code></pre>
  
  <p>Python thinks I'm importing a directory named 'foo' rather than foo.py.  I tried to mess with <strong>init</strong>.py business to no avail.</p>
  
  <p>Is there a way to get around this issue?  I find it quite annoying that Python cannot distinguish between directory foo vs file foo.py.</p>
  
  <p>EDIT:
  I think I was missing an important piece.  I am sourcing the modules/ directory via my unit tests, so the entire directory structure looks like so:</p>
  
  <pre><code>modules/foo.py
  modules/foo/bar.py
  modules/foo/baz.py
  tests/unit.py
  </code></pre>
  
  <p>In unit.py, I have the following:</p>
  
  <pre><code>#!/usr/bin/python
  
  import sys
  import os
  
  findbin = os.path.abspath(os.path.dirname(sys.argv[0]))
  sys.path.append(findbin + "/../modules")
  
  from foo import Foo
  
  obj = Foo()
  </code></pre>
  
  <p>When I run this, I get:</p>
  
  <pre><code>from foo import Foo
  ImportError: cannot import name Foo
  </code></pre>