title: Python import : AttributeError: 'module' object has no attribute 'test'
body: <p>I think that's stupid problem, but I can't figure out why I get the following</p>
  
  <pre><code>AttributeError: 'module' object has no attribute 'test'
  </code></pre>
  
  <p>when running my <strong>test3.py</strong>.</p>
  
  <p>Here is my project tree :</p>
  
  <pre><code>.
  ├── __init__.py
  ├── test3.py
  └── testdir
      ├── __init__.py
      └── test.py
  </code></pre>
  
  <p>My <strong>test3.py</strong> :</p>
  
  <pre><code>#!/usr/bin/python                                                          
  
  import testdir
  
  if __name__ == "__main__":
      print(testdir.test.VAR)
  </code></pre>
  
  <p>My <strong>test.py</strong> :</p>
  
  <pre><code>#!/usr/bin/python
  
  import os
  
  VAR=os.path.abspath(__file__)
  </code></pre>
  
  <p>I also tried to import my <strong>VAR</strong> this way :</p>
  
  <pre><code>from testdir.test import VAR
  </code></pre>
  
  <p><strong>EDIT:</strong> Now this one works -thanks to @user2357112- but I would still like to know how to import the whole test.py file without a <code>from ... import ...</code> if it is possible. :)</p>
  
  <p>And I tried a <code>import ..testdir</code> to do a relative import but I got a <code>SyntaxError</code>.</p>
  
  <p>And if I try <code>import testdir.test</code> I get a <code>NameError: name'test' is not defined</code>.</p>
  
  <p>How could I import this file? I'm a bit confused.</p>
  
  <p><strong>EDIT bis :</strong></p>
  
  <p>I apologize, when I tried <code>import testdir.test</code>, I also modified <code>print(testdir.test.VAR)</code> to <code>print(test.VAR)</code>.</p>
  
  <p>That was the problem, my bad.</p>
  
  <p>with :</p>
  
  <pre><code>#!/usr/bin/python                                                          
  
  import testdir.test
  
  if __name__ == "__main__":
      print(testdir.test.VAR)
  </code></pre>
  
  <p>It works perfectly, I though that importing <code>testdir.test</code> made <code>test</code> exist alone (and not <code>testdir.test</code>) in the scope.</p>
  
  <p>Sorry for the inconvenience. :S</p>