Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

TypeError: 'module' object is not callable in Python

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

what is the reason for this error?
by

2 Answers

Bharatgxwzm
Accept that the substance of YourClass.py is:.

class YourClass:
# ......

from YourClassParentDir import YourClass  # means YourClass.py

Along these lines, you will get TypeError: 'module' object isn't callable on the off chance that you, attempted to call YourClass().
But, if you apply:
from YourClassParentDir.YourClass import YourClass   # means Class YourClass

or use YourClass.YourClass(), it works.
Sonali7
This kind of error generally occurs when you try to import a module thinking of it as a function and call it. So in Python, a module is a .py file. Packages(directories) can also be considered as modules.
Suppose there is a create.py file. In that file there is a function like this:
#inside create.py
def create():
pass


Now there is another code like:
#inside main.py file
import create
create()

Here, create refers to create.py, so create.create() would work here.

But it will give an error if the create.py is called as a function. So, to overcome this situation we have to do the following
from create import create
create()

Login / Signup to Answer the Question.