Home >Backend Development >Python Tutorial >How Do I Fix the \'TypeError: \'module\' object is not callable\' Error with the `socket` Module?
"TypeError: 'module' object is not callable"
This error message typically occurs when you attempt to call a module as a callable. In your case, you're trying to call the socket module, which is an object that contains classes and functions.
To solve this error, you need to call the socket class within the module. There are two ways to do this:
Option 1: Use the fully qualified name:
self.serv = socket.socket(AF_INET,SOCK_STREAM)
Option 2: Import the socket class explicitly:
from socket import socket self.serv = socket(AF_INET, SOCK_STREAM)
By using either of these methods, you're specifying that you want to call the socket class within the socket module,而不是模块本身。
The above is the detailed content of How Do I Fix the 'TypeError: 'module' object is not callable' Error with the `socket` Module?. For more information, please follow other related articles on the PHP Chinese website!