JavaScript
x
6
1
* myproject
2
+ getdir
3
- somename.py
4
+ pushdir
5
- nicename.py
6
I’m trying to import a class from somename.py into nicename.py.
At first I created the the __init__.py
file and left it empty.
Then I wrote (in nicename.py):
JavaScript
1
2
1
from ..getdir.somename import classnameexample
2
and I also tried the command without double points at first.
It returns:
ModuleNotFoundError: No module named ‘getdir’
Advertisement
Answer
Maybe not the most elegant but you can add the path in sys.path
before importing getdir
:
JavaScript
1
4
1
import sys
2
sys.path.append('..')
3
from getdir import somename #Now python will look for getdir in sys.path, including at '../'
4