521 views, 0 RAMs, and 2 comments
I am working on some programming in Python but I'm hitting some object call problems (typeerror: 'module' object is not callable). I don't know what mistake(s) I'm making that's causing this to happen. Any programmers out there who can help me understand why this won't work?
This is a debug account.
In Python, you need to distinct between module names and class names. The problem is in the import line . You are importing a module, not a class. This happend because the module name and class name have the same name .
If you have a class MyClass in a file called MyClass.py , then you should write:
from MyClass import MyClass
In Python , a script is a module, whose name is determined by the filename . So when you start out your file MyClass.py with import MyClass you are creating a loop in the module structure. The error 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.
This error is likely occurring because of code that involves a module that contains a function that has the same name as the module. For example, the
datetime module includes a function called "
datetime" and can be imported/called as follows:
# Works correctly from datetime import datetime datetime(2011, 11, 4, 0, 0)
# Also works correctly import datetime datetime.datetime(2011, 11, 4, 0, 0)
Whereas this will cause an error:
# Throws an error: import datetime datetime(2011, 11, 4, 0, 0) # Traceback (most recent call last): # File "<stdin>", line 1, in <module> # TypeError: 'module' object is not callable
There are also other similar modules that contain classes/functions that have the same name as the packet, such as
socket and the module's function
Sir, I can do you a nice SEO.
Post a New Comment
Do you like having a good time?
Register an Account
Read Quality Articles
Read some quality articles. If you can manage to not get banned for like five minutes, you can even post your own articles.
Argue with People on the Internet
Use your account to explain why people are wrong on the Internet forum.
Vandalize the Wiki
Or don't. I'm not your dad.
Ask and/or Answer Questions
If someone asks a terrible question, post a LMGTFY link.
Make Some Money
Hire freelancers and/or advertise your goods and/or services. Hire people directly. We're not a middleman or your dad. Manage your own business transactions.
Answers— Read More
Find more related content below!
- I very much agree with this sentence.
- [Python] Solution to "ValueError: unknown label type: 'continuous' or 'unknown'?"...
- [Python] Help with "ValueError: length of values does not match length of index?"
- [Python] Help with "ValueError: cannot reindex from a duplicate axis?"
- [Python] Solution to "ValueError: cannot convert float nan to integer?"
- [Python] Solution to "TypeError: a bytes-like object is required, not 'str'?"
- [Python] How to fix "TypeError: 'str' object does not support item assignment?"
- [Python] Help with "TypeError: 'float' object cannot be interpreted as an integer?"
- [Python] Fix for "NameError: name 'xrange' is not defined?"