Python:'module'对象不可调用

Jai*_*era 2 python exception

我定义了一个异常类

#####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)
Run Code Online (Sandbox Code Playgroud)

文件名是:"UniqueConstraintException.py"和包名:"exception"

我正在以这种方式导入和使用它:

from exception import UniqueConstraintException

raise UniqueConstraintException(prop_key)
Run Code Online (Sandbox Code Playgroud)

并得到此错误:

TypeError: 'module' object is not callable
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

Mar*_*ers 9

这就是为什么要保持模块名称较低的原因.:-)

from exception.UniqueConstraintException import UniqueConstraintException
Run Code Online (Sandbox Code Playgroud)

您导入了模块,没有在模块内部定义的类.