I am currently working on a project, and this is my directory's current structure:
ProjectFolder
|-ResultsFolder
| |-results.py
|
|-HelperFolder
| |-init.py
| |-helper1.py
| |-helper2.py
|
|-out.py
HelperFolder is a package I made to help me out with a few commonly used function. Helper1.py and helper2.py contain these functions (~ 5 each) based on how the functions are used and if any functions use each other.
I have my main.py in a results folder, and I wish to import helper1 and helper2 as h1 and h2 respectively.
I tried the following import statements:
import ..HelperFolder.helper1 as h1
from ..HelperFolder import helper1 as h1
from .HelperFolder import helper1 as h1
But all of them are giving me errors. The from ..HelperFolder import helper1 as h1 gives me an error of an invalid syntax at .., while the other imports give me ImportError: attempted relative import with no known parent package.
Please help me out, as to how can I import helper1.py and helper2.py into main.py?
Note :
If I use a python file such as out.py outside of any folder/directory, then I can harmlessly import helper1 and helper2 as:
from HelperFolder import helper1 as h1
from HelperFolder import helper2 as h2
I want to know what is the correct import if I have files at different levels in multiple directories, and I wish to import files there.