title: Import Python module from different folders
body: <p>I see the question I am going to ask is a very trivial one and has been asked and consequently answered by many. I have looked through the solution provided for the problem, however I don't see the solution to work in my case.</p>
  
  <p>I have the following directory hierarchy.</p>
  
  <pre><code>----a
  -------__init__.py
  --------------aa
  ------------------aa.py
  ------------------__init__.py
  --------------bb
  ------------------bb.py
  ------------------__init__.py
  -------a.py
  </code></pre>
  
  <p>I would like to do the following.</p>
  
  <ol>
  <li>To import bb.py and aa.py from the file a.py-- accomplished by using __init__.py in each folder directory</li>
  <li>TO import bb.py from aa.py  (Doesn't work)</li>
  <li>TO import a.py from aa.py   (Doesn't work)</li>
  </ol>
  
  <p>By looking at many solutions I have placed the <code>__init__.py</code> file inside every folder directory.</p>
  
  <p>I  used:</p>
  
  <pre><code>import imp
  
  foo = imp.load_source('module.name', 'path to the file') 
  </code></pre>
  
  <p>This worked, but since the path has to be hard-coded I am not sure if this will be a viable solution in my case</p>
  
  <p>Currently I am doing the imports by adding the path to the sys directories. I'd like a solution that's more dynamic.</p>
  
  <p>The folder hierarchy of my project goes deep to 6-7 levels sub-directories and I need a solution to import a module at level 1 from level 7.</p>
  
  <p>I'll be glad if somebody could point out what I am missing.</p>