Im getting a message from pycodestyles in VisualStudio that sais 'module level import not at top of file'. This is because, in my company, there is this big project that looks like this:
- Main Folder
- Project1
- Project2
- Utils
- Utils.py
- MyModule
- MyWorkingDirectory
- Myfile.py
- MyWorkingDirectory
- AnotherModule
- Utils
So I need to use functions in the Utils.py that are going to be shared from different modules (MyModule & AnotherModule in this case). I have been reading a lot about python imports (stackoverflow is full of this kind of questions, maybe we should start thinking this is a not very friendly way to do it..) so I did this:
import sys
sys.path.append(str(Path(__file__).resolve().parents[2]))
from utils.utils import *
My question is: is there a good way of doing this without restructuring the project? I have read a lot of workarounds, but I would like to know if there is a common-standard-good-way of resolving this.
I'm using Python 3.10.7.
Thanks in advance