Home > Enterprise >  how to import file when you are in another folder ? python
how to import file when you are in another folder ? python

Time:05-05

My question is when I am in the test_func1.py how to import func1.py

├───core
     - func1.py 
├───tests
     - test_func1.py 

CodePudding user response:

One solution is sys.path:

import sys
from pathlib import Path
sys.path.append(str(Path(__file__).parent.resolve().parent/'core'))
import func1
  • Related