Reputation: 1739
In my working folder I have a file called exceptions.py, which contains only:
class ParseException(Exception):
pass
class QueryException(Exception):
pass
In the same folder I have a file, lets call it my_script.py
In my_script.py, when I do from exceptions import ParseException
I get an error:
ImportError: cannot import name ParseException
I cannot figure out what's going on here. I've never seen this error before, and when I looked it up I mainly see problems with circular dependencies, but I don't have any here...
Upvotes: 2
Views: 3325
Reputation: 44838
There is the exceptions
module in your Python library which doesn't have the methods/classes you're trying to import. Change your file name to something different and it'll work.
Try the following yourself
>>> import exceptions
# Works OK
>>> from exceptions import ParseException
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: cannot import name ParseException
>>> from exceptions import ImportError # Works OK too
Upvotes: 5