[Python] Sharing objects across package

Discussão em 'Python' iniciado por Stack, Julho 24, 2025.

  1. Stack

    Stack Membro Participativo

    I have this module that over time has become too large, with classes that do not need to be in the same file. So I decided to split into a package.

    The end result would be something like this:

    \---asset
    | controller.py
    | discover.py
    | __init__.py
    |
    \---reporting
    servers.py
    __init__.py


    The issue is that there are a couple objects, constants, decorators and logging configuration (basicConfig and getLogger), that I need to be accessible from every file in the package. Can it be achieved using __init__.py files? I've tried this before and always run into circular import issues.

    Additionally I would like to ask if there is a more elegant solution to the following to make the directory recognised as a package:

    import sys

    sys.path.append('./asset')

    Continue reading...

Compartilhe esta Página