'how to import file when you are in another folder ? python

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

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



Solution 1:[1]

One solution is sys.path:

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Waket Zheng