Python Script Error in Windows 7
<p>I am trying to run this following script in here and getting this NameError. I have added path variable in Windows 7. </p>

<pre><code>C:\Users\myname&gt;python
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:01:18) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.

&gt;&gt;&gt; script.py
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
NameError: name 'script' is not defined
</code></pre>

<p>This is the script I am trying to run : </p>

<pre><code>#!/usr/bin/python
import sys, string, time
from socket import *
host = "192.168.0.98"
port = 80
print "Open TCP connections to: %s, port %s" % (host, port)
while (1):
    s = socket(AF_INET,SOCK_STREAM)
    s.connect((host, port))
    s.send("abc")    
### test: donot close.  s.close()  
time.sleep(0.1)
print ".",
</code></pre>

<p>Thank you all. </p>

<p>You need to do <code>python script.py</code> instead, from the command prompt <em>not</em> from the Python interpreter. </p>

<p>However, if you are in the Python interactive interpretor in the same directory as your script, as <strong>@Tuan333</strong> points out, you can do:</p>

<pre><code>&gt;&gt;&gt; import script
</code></pre>

<p>or </p>

<pre><code>&gt;&gt;&gt; from script import something
</code></pre>

<p>to get access to functions and classes defined in the script (note that it is <code>script</code> in this case, not <code>script.py</code> because you are treating it as a module). However, as <strong>@ÅukaszRogalski</strong> points out, this is not equivalent to running the script from the command prompt as described above.</p>

python python-3.x