[Python] What is __path__ useful for?

Discussão em 'Python' iniciado por Stack, Novembro 27, 2025.

  1. Stack

    Stack Membro Participativo

    I had never noticed the __path__ attribute that gets defined on some of my packages before today. According to the documentation:


    Packages support one more special attribute, __path__. This is initialized to be a list containing the name of the directory holding the package’s __init__.py before the code in that file is executed. This variable can be modified; doing so affects future searches for modules and subpackages contained in the package.

    While this feature is not often needed, it can be used to extend the set of modules found in a package.
    ​

    Could somebody explain to me what exactly this means and why I would ever want to use it?

    Continue reading...

Compartilhe esta Página