我想在這裏運行以下腳本並獲取此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