简体   繁体   English

Python:'module'对象不可调用

[英]Python: 'module' object is not callable

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" 文件名是:“UniqueConstraintException.py”和包名:“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? 我究竟做错了什么?

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. 您导入了模块,没有在模块内部定义的类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM