Reputation: 85
I have this strucutre:
app/src/main.py
app/test/test.py
I want to import a function from main.py to test.py
I tried adding __init__.py
to the parent lib and also the directories but it gave me an error.
the error is:
ModuleNotFoundError: No module named 'app'
Upvotes: 1
Views: 80
Reputation: 1845
Try this:
import sys; sys.path.insert(1, os.path.join(sys.path[0], '..'))
sys.path.append('../src/')
import src.main as mainfn
mainfn.function()
change function()
with the name of your function
Upvotes: 2