relative import from utility script in subdirectory

Viewed 70

From reading over other answers, it seems that possibly my layout is "un-Pythonic," although I'm really not quite sure. If so that would be helpful to know, along with a suggestion for the better layout.

Here is my script layout:

/
__init__.py
main_prog.py
utilities.py
    /support_scripts
    support_utility1.py
    support_utility2.py
    ...

The support utilities contain functionality which are related to main_prog.py, but are best placed in their own scripts. Since there are many of them, I have moved them in their own directory. But they use some of the same functionality from utilities.py

When I try to import using from .. import utilities I get the error message "ValueError: attempted relative import beyond top-level package"

Now my first question would simply be: Is it considered bad to try to place additional scripts in subdirectories like this? Knowing a general principle like that would go a long way to solving my problems. And of course if you have any specific suggestions that will help too.

0 Answers
Related