Python:“模块"对象不可调用 [英] Python: 'module' object is not callable

查看:131
本文介绍了Python:“模块"对象不可调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我定义了一个异常类

#####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)

文件名:"UniqueConstraintException.py",包名:"exception"

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)

并得到此错误:

TypeError: 'module' object is not callable

我在做什么错了?

推荐答案

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

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.

这篇关于Python:“模块"对象不可调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆