Python: 'module' object is not callable

。_饼干妹妹 提交于 2021-02-08 02:36:41

问题


I have an exception class defined

#####UNIQUE CONSTRAINT EXCEPTION#########################################################3
class UniqueConstraintException (Exception):
    def __init__(self, value):
        self.value = value

    def __str__(self):
        return repr('Failed unique property. Property name: ' + self.value)

The file name is: "UniqueConstraintException.py" and package name: "exception"

I'm importing and using it in this way:

from exception import UniqueConstraintException

raise UniqueConstraintException(prop_key)

And get this error:

TypeError: 'module' object is not callable

What am i doing wrong?


回答1:


This is why you want to keep your module names lower-cased. :-)

from exception.UniqueConstraintException import UniqueConstraintException

You imported the module, no the class defined inside of the module.



来源:https://stackoverflow.com/questions/12094613/python-module-object-is-not-callable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!