问题
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