[Python] What's the best way to import a module from a directory that's not a package? [closed]

Discussão em 'Python' iniciado por Stack, Janeiro 28, 2025.

  1. Stack

    Stack Membro Participativo

    My directory structure:

    dir/
    build.py
    dir2
    dir3/
    packages.py


    build.py needs packages.py. dir2 is not a package. What's the best way to get packages.py loaded into build.py (the directory structure can't be changed)?

    The sys.path.append solution seems good but I need to use the packages.py file rarely and keeping a sys.path that includes a directory used rarely, but is at the front, is that the best thing?

    Continue reading...

Compartilhe esta Página