Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error with __init__ 'module' object is not callable

Tags:

python

I was creating my module and when I tested it, I got an error. The code was like this:

class test:
    def __init__(self,size,type):
        self.type = type
        self.size = size

And after I import the module, when I type:

x=test(10,'A type')

It says:

TypeError: 'module' object is not callable

Please help me.

like image 521
Lucas Menicucci Avatar asked May 20 '12 02:05

Lucas Menicucci


People also ask

How do I fix Python module object is not callable error?

How to fix typeerror: 'module' object is not callable? To fix this error, we need to change the import statement in “mycode.py” file and specify a specific function in our import statement.

What is the meaning of module object is not callable?

It 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.

Why is object not callable Python?

The “int object is not callable” error occurs when you declare a variable and name it with a built-in function name such as int() , sum() , max() , and others. The error also occurs when you don't specify an arithmetic operator while performing a mathematical operation.

Why is my DataFrame object not callable?

The TypeError 'DataFrame' object is not callable occurs when you try to call a DataFrame as if it were a function. TypeErrors occur when you attempt to perform an illegal operation for a specific data type. To solve this error, ensure that there are no parentheses after the DataFrames in your code.


1 Answers

You didn't paste your import, but I'm betting you used

import test

where your file is called test.py (which should probably be more descriptive, BTW) which imports the module, which is why it's objecting that test is a module object and isn't callable. You can access your class by calling

x = test.test(10, "A type")

or alternatively you could use

from test import test

after which

x = test(10, "A type") 

should work.

like image 173
DSM Avatar answered Sep 30 '22 03:09

DSM