我一直在尝试 Python 中的“套接字”模块,但每当我尝试运行此代码时:
import socket
import sys
host = '192.168.1.1'
port = 23
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
except:
print "socket() failed"
sys.exit(1)
然后它就死了。这是没有 except 和 try 的错误:
Traceback (most recent call last):
File "C:\Documents and Settings\a\Desktop\socket.py", line 1, in <module>
import socket
File "C:\Documents and Settings\a\Desktop\socket.py", line 6, in <module>
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
AttributeError: 'module' object has no attribute 'AF_INET'
我刚刚开始使用 Python(今天)并且需要帮助。
我将它保存为 socket.py 但也保存为 sock.py ...