256 Kilobytes

Answers in Scripting and Automation | By Some Guy

Published

299 views, 0 RAMs, and 2 comments

Tags: Python, Errors, Module, Programming

Profile Photo - Some GuySome GuyBasic Subscriber

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?

Download more RAM. 🐏 ⨉ 0Posted by Some Guy 1 year ago 🕓 Posted at 16 December, 2018 09:37 AM PST

This is a debug account.

Profile Photo - Defaulthlipperjohn

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.

Download more RAM. 🐏 ⨉ 0Posted by hlipperjohn 6 months ago 🕓 Posted at 30 December, 2019 21:06 PM PST
Profile Photo - August R. GarciaAugust R. GarciaLARPing as a Sysadmi...Portland, ORSite Owner

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)

Or:

# 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 socket.socket().

Download more RAM. 🐏 ⨉ 0Posted by August R. Garcia 6 months ago

Edit History

• [2019-12-31 10:29 PST] August R. Garcia (6 months ago)
🕓 Posted at 31 December, 2019 10:29 AM PST

Sir, I can do you a nice SEO.

Post a New Comment

Do you like having a good time?

Register an Account

You can also login to an existing account or reset your password. All use of this site is subject to the terms of service and privacy policy.

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.

View Articles →

Argue with People on the Internet

Use your account to explain why people are wrong on the Internet forum.

View Forum →

Vandalize the Wiki

Or don't. I'm not your dad.

View Wiki →

Ask and/or Answer Questions

If someone asks a terrible question, post a LMGTFY link.

View Answers →

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.

Register an Account

Answers— Read More

Find more related content below!