title: NameError: name 'runfile' is not defined only when running from script
body: <p>sima.py</p>
  
  <pre><code>import pyautogui as py
  py.alert("Foo")
  </code></pre>
  
  <p>simaref.py</p>
  
  <pre><code>runfile('E:/Anyagok/Programozas/Python/projekts/gyak/Pyautogui/sima.py', 
          wdir='E:/Anyagok/Programozas/Python/projekts/gyak/Pyautogui')
  </code></pre>
  
  <p>These both work when running from Spyder.  </p>
  
  <p>sima.py works from cmd as well:</p>
  
  <pre><code>python.exe E:\Anyagok\Programozas\Python\projekts\gyak\Pyautogui\sima.py
  </code></pre>
  
  <p>But simaref.py doesn't:</p>
  
  <pre><code>E:\Download\PROGIK\ANACONDA&gt;python.exe E:\Anyagok\Programozas\Python\projekts\gyak\Pyautogui\simaref.py
  Traceback (most recent call last):
    File "E:\Anyagok\Programozas\Python\projekts\gyak\Pyautogui\simaref.py", line 8, in &lt;module&gt;
      runfile('E:/Anyagok/Programozas/Python/projekts/gyak/Pyautogui/sima.py', wdir='E:/Anyagok/Programozas/Python/projekts/gyak/Pyautogui')
  NameError: name 'runfile' is not defined
  </code></pre>
  
  <p>Why not?</p>
  
  <p>Edit:
  Got the idea of runfile() from: when running code in Spyder, in the console it displays e.g.:  </p>
  
  <pre><code>runfile('E:/Anyagok/Programozas/Python/projekts/gyak/Pyautogui/simaref.py', wdir='E:/Anyagok/Programozas/Python/projekts/gyak/Pyautogui')
  </code></pre>