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\", line 82, in __init__
self.serv = socket(AF_INET,SOCK_STREAM)
TypeError: 'module' object is not callable

what is the reason for this error?

2 Answers

Accept that the substance of is:.

class YourClass:
# ......

from YourClassParentDir import YourClass  # means

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.
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 file. In that file there is a function like this:
def create():

Now there is another code like:
#inside file
import create

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

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

Login / Signup to Answer the Question.