0

I got ImportError: cannot import name Empty when I tried to import a subclass of Exception. Here is the code:

file name: exceptions.py

class Empty(Exception):
  """Error attempting to access an element from an empty container."""
  pass

file name: main.py

from exceptions import Empty

How can I fix this?

juanpa.arrivillaga
  • 88,713
  • 10
  • 131
  • 172
AlexBains
  • 295
  • 6
  • 14
  • did you read this? https://stackoverflow.com/questions/1319615/proper-way-to-declare-custom-exceptions-in-modern-python – developer_hatch Nov 25 '17 at 23:43
  • 1
    Where are your files located, and how are you running `main.py`? Is there another `exceptions.py` file around somewhere, with different contents? The message suggests that it's not finding the `exceptions` module you expect it to find. – Blckknght Nov 26 '17 at 00:00
  • 1
    Try `import exceptions;print(exceptions.__file__)` to find out the path to the module and check if it's the right one. – Michael Butscher Nov 26 '17 at 00:02

0 Answers0