"from" import works differently
<p>I have this code in my Python code (<code>settings.py</code> is located in the <code>PROJECT</code> dir):</p>

<pre><code>import PROJECT.settings
...
if PROJECT.settings.BASE_DIR:
   ...
</code></pre>

<p>which works fine. I'd say I could rewrite to this:</p>

<pre><code>from PROJECT import settings
...
if settings.BASE_DIR:
   ...
</code></pre>

<p>But that gives an <code>AttributeError: 'NoneType' object has no attribute 'BASE_DIR'</code></p>

<p>Am I missing something here?</p>

<p>The <code>from parent import name</code> format first looks for names in the <code>module</code> namespace (set in <code>__init__.py</code> or anything that added that name to the <code>parent</code> module).</p>

<p>In your case, the <code>__init__.py</code> file in <code>PROJECT</code> has set <code>settings</code> to <code>None</code>. It is this name that is found before any contained modules.</p>

<p>The <code>import parent.name</code> form will only look for modules in a package, not for names defined in the <code>parent</code> module.</p>

python