标签归档文章: socket

python: TypeError: ‘module’ object is not callable

Question:

File "C:\Users\Administrator\Documents\Mibot\oops\blinkserv.py", line 82, in __init__
self.serv = socket(AF_INET,SOCK_STREAM)
TypeError: 'module' object is not callable

socket is a module, 包含 class socket.

Answer:

使用socket.socket(…)

或者一开始import socket class
from socket import socket:

下面为具体的代码例子:

所以我们可以这样 socket.socket(...)  或者在开始的地方 from socket import socket:

>>> import socket
>>> socket

>>> socket.socket

>>>
>>> from socket import socket
>>> socket