Relative Python Modules
<p>I am having a lot of trouble understanding the python module import system.</p>

<p>I am trying to create a simple folder structure as follows.</p>

<pre><code>SomeModule
   __init__.py
   AnotherModule
       AnotherModule.py
       __init__.py
       Utils
           Utils.py
           __init__.py
</code></pre>

<p>To use SomeModule i can do:</p>

<pre><code>SomeModule.Foo()
</code></pre>

<p>Now inside AnotherModule.py I would like to import my Utils directory.</p>

<p>How come I have to do</p>

<pre><code>import SomeModule.AnotherModule.Utils.Foo
</code></pre>

<p>why cannot I just do</p>

<pre><code>import Utils.Foo
</code></pre>

<p>To shorten up the actual function name that you'll have to call in your code, you can always do:</p>

<pre><code>from SomeModule.AnotherModule.Utils import *
</code></pre>

<p>While this still won't allow you to get away with a shorter import statement at the top of your script, you'll be able to access all of the functions within <code>.Utils</code> just by calling their function name (i.e. <code>foo(x)</code> instead of <code>SomeModule.AnotherModule.Utils.foo(x)</code>. </p>

<p>Part of the reason for the lengthy import statement goes to the comment from @wim . Have a look by typing <code>import this</code> in a python interpreter.  </p>

python python-2.7