Home >Backend Development >Python Tutorial >Why Does Python Throw a \'TypeError: \'module\' object is not callable\' Error?
TypeError: 'module' object is not callable in Python
The error message "TypeError: 'module' object is not callable" occurs when you attempt to call a module object as a function. A module object is the type of object you get when you import a module, and it is not callable. What you need to do is to call a class object within the module object that happens to have the same name as the module that contains it.
For example, the following code will generate the error:
import socket socket()
This is because socket is a module object, and it cannot be called as a function. To call the socket class, you need to do the following:
import socket socket.socket()
Or:
from socket import socket socket()
Here is a way to logically break down this sort of error:
By following these steps, you can quickly identify the source of the error and find a solution.
The above is the detailed content of Why Does Python Throw a \'TypeError: \'module\' object is not callable\' Error?. For more information, please follow other related articles on the PHP Chinese website!