mydir └ parent.py └ child.py
How to import parent.py from child.py in a folder structure such as
child.py
import sys
import pathlib
#Get the absolute path of the next higher hierarchy
parent_dir = str(pathlib.Path(__file__).parent.parent.resolve())
#Add the absolute path of the next higher hierarchy to the module search path
sys.path.append(parent_dir)
import parent
Recommended Posts