256 Kilobytes

Answers in Scripting and Automation | By Some Guy

Published 1 year agoSun, 16 Dec 2018 09:37:24 -0800

213 views, 0 RAMs, and 2 comments

Tags: Python, Errors, Module, Programming

Profile Photo - Some Guy Some Guy
🗎 3224 🗨 43 🐏 31
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. 🐏 ⨉ 0 Posted by Some Guy 1 year ago 🕓 Posted at 16 December, 2018 09:37 AM PST

This is a patsy account used by the 256 Kilobytes staff to seed content. 

Profile Photo - Default hlipperjohn
🗎 0 🗨 1 🐏 0

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. 🐏 ⨉ 0 Posted by hlipperjohn 1 month ago 🕓 Posted at 30 December, 2019 21:06 PM PST
Profile Photo - August R. Garcia August R. Garcia LARPing as a Sysadmi... Portland, OR
🗎 211 🗨 1094 🐏 328
Site 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. 🐏 ⨉ 0 Posted by August R. Garcia 1 month ago

Edit History

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

Sir, I can do you a nice SEO.

Post a New Comment

To leave a comment, login to your account or create an account.

Do you like having a good time?

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
You can also login to an existing account or recover your password. All use of this site is subject to terms outlined in the terms of service and privacy policy.