AttributeError: type object '_socketobject' has no attribute 'socket'

代码:

------------------------------------------------

from socket import *

host = ""
port = 99999
addr = (host,port)
tcpSock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
tcpSock.bind(addr)
tcpSock.listen(5)

 

错误:

-------------------------------------------------

Traceback (most recent call last):
  File "/home/fedora11/NetBeansProjects/myTcpServer/src/mytcpserver.py", line 16, in
    tcpSock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
AttributeError: type object '_socketobject' has no attribute 'socket'

 

原因:

-------------------------------------------------

tcpSock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)

这句有问题,修改为:

tcpSock = socket(AF_INET,.SOCK_DGRAM)

即可!

 

python书写方式极度简单,语法也很简单,不像C++要求那么严格!呵呵!

 

你可能感兴趣的:(socket,object,python,module,import,file)