[Python] Creating exception classes in __init__.py [closed]

Discussão em 'Python' iniciado por Stack, Junho 17, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to learn how raising and handling errors works in packages and saw that in Pandas they define most of the Exception Classes in the __init__.py with only two messages getting put into a separate .py file in the errors folder.

    I thought that the __init__.py had two primary purposes. A) To tell python that this folder has code in it and should be treated as a package. (which is no longer needed in more recent versions of python) B) To control the imports by defining __all__ = [...]

    But for the most part, the __init.py can be left empty. So can someone explain why Pandas uses their __init__.py instead of creating exceptions.py (or something) within the errors folder?

    Continue reading...

Compartilhe esta Página