DEV Community

Hyunjin Cho
Hyunjin Cho

Posted on • Updated on

[Python] TypeError 'module' object is not callable in Python

'module' object is not callable

-> when module name and class name are confused, this error raised

For example,

I have DBCM class inside dbcm.py and import DBCM class like this,

import dbcm

# do something with dbcm
with dbcm(slef.db_name, sql):
 .....
Enter fullscreen mode Exit fullscreen mode

It will raise that typeerror.

How to solve it,

Be clear which one is module and which one is class

from dbcm import DBCM as db_cm

with db_cm(self.db_name, sql):
 ....
Enter fullscreen mode Exit fullscreen mode

Modified by Keoni Garner - Thank you!:

from dbcm import DBCM

with DBCM(self.db_name, sql):
 ....
Enter fullscreen mode Exit fullscreen mode

Resource: https://www.stechies.com/typeerror-module-object-is-not-callable/

Top comments (1)

Collapse
 
hyunjin profile image
Hyunjin Cho • Edited

yeah that's right. I thought it's up to the writer whether to write or not. I'm now keeping learning so thank you for ur comment!