我想在这里运行以下脚本并获取此NameError。我已经加入PATH变量在Windows 7Windows 7中的Python脚本错误
C:\Users\myname>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.
>>> script.py
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'script' is not defined
这是我试图运行脚本:
#!/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 ".",
谢谢大家。
您试图运行脚本在交互式python shell中输入文件名(启动'python'后)。在Windows的'cmd'中试试'python script.py'。 –
您的代码中有一个小错字。在打印语句之后,您可以在末尾删除','。 – albert