title: Python import behaviour and 'NoneType' object has no attribute
body: <p>Can anyone clarify the following behavior. I ran into it in a bigger piece of code, but I created a minimal example</p>
  
  <p>File <code>untitled0.py</code> consists of the following code:</p>
  
  <pre><code>import numpy as np
  class A:
      def f(self,x):
          return np.diag(x)
  </code></pre>
  
  <p>File <code>untitled1.py</code> consists of the following code:</p>
  
  <pre><code>import untitled0 as u0
  import numpy as np
  a=u0.A()
  print a.f([1])
  </code></pre>
  
  <p>The output is simple and [[1]] is printed on the screen. Now suppose you have created <code>a</code> (an instance of A) with a lot of computational effort and continue writing your script and don't want to recompute all the time. What I then normally do is simply commenting out the creation line (since the object a is already exists in you python shell anyway), i.e.: </p>
  
  <pre><code>import untitled0 as u0
  import numpy as np
  #a=u0.A()
  print a.f([1])
  </code></pre>
  
  <p>However, when I run this script it leads to the error:</p>
  
  <pre><code>UMD has deleted: untitled0
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
    File "C:\WinPython-64bit-2.7.5.1\python-2.7.5.amd64\lib\site-packages\spyderlib\widgets\externalshell   \sitecustomize.py", line 523, in runfile
      execfile(filename, namespace)
    File "M:\....\untitled1.py", line 12, in &lt;module&gt;
      print a.f([1])
    File "untitled0.py", line 12, in f
      return np.diag(x)
  AttributeError: 'NoneType' object has no attribute 'diag'
  </code></pre>
  
  <p>For some reason <code>np</code> is not defined inside <code>untitled0.py</code>. Can anyone explain what happened?</p>