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
Why am I getting this error? I'm confused.
What do you need to know to answer my question?
The Python "TypeError: 'module' object is not callable" occurs when we import a module as import some_module but try to call it as a function or class. To solve the error, use dot notation to access the specific function or class before calling it, e.g. module. my_func() .
It says module object is not callable, because your code is calling a module object. A module object is the type of thing you get when you import a module. What you were trying 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.
But in Python, this would lead to the Typeerror: int object is not callable error. To fix this error, you need to let Python know you want to multiply the number outside the parentheses with the sum of the numbers inside the parentheses. Python allows you to specify any arithmetic sign before the opening parenthesis.
The TypeError: 'module' object is not callable error occurs when python is confused between the class object and module. Python attempts to invoke a module as an instance of a class or as a function. This TypeError: 'module' object is not callable error occurs when class and module have the same name.
socket
is a module, containing the class socket
.
You need to do socket.socket(...)
or from socket import socket
:
>>> import socket >>> socket <module 'socket' from 'C:\Python27\lib\socket.pyc'> >>> socket.socket <class 'socket._socketobject'> >>> >>> from socket import socket >>> socket <class 'socket._socketobject'>
This is what the error message means:
It says module object is not callable
, because your code is calling a module object. A module object is the type of thing you get when you import a module. What you were trying 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.
Here is a way to logically break down this sort of error:
module object is not callable
. Python is telling me my code trying to call something that cannot be called. What is my code trying to call?"socket
. That should be callable! Is the variable socket
is what I think it is?`print socket
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With