Lucas Menicucci
Lucas Menicucci

Reputation: 477

Error with __init__ 'module' object is not callable

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.

Upvotes: 8

Views: 11003

Answers (3)

Jon
Jon

Reputation: 3502

Not the problem in this case, but if you get this error make sure you spelled init correctly. I had int with a missing i and it took awhile to notice.

Upvotes: 2

Jeffery Thomas
Jeffery Thomas

Reputation: 42598

I think you have an indent problem.

Try indenting the def.

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

Upvotes: 0

DSM
DSM

Reputation: 353499

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.

Upvotes: 32

Related Questions