Which of the following describes the behavior of from [...] import [...]
?
- cwd first: look in working directory first, then the path
- path first: look in the path, then the working directory
Consider the following scripts:
Change Path
sys.path.insert(0, 'E:\\demo_dir\\example_dir\\eg_dir\\test_dir\\')
from src import name
sys.path.pop(0)
Change Cwd
old_cwd = os.getcwd()
os.chdir('E:\\demo_dir\\example_dir\\eg_dir\\test_dir\\')
from src import name
os.chdir(old_cwd)
Combined Script
old_cwd = os.getcwd(); os.chdir('E:\\demo_dir\\example_dir\\eg_dir\\test_dir\\')
sys.path.insert(0, 'E:\\demo_dir\\example_dir\\eg_dir\\test_dir\\')
from src import name
os.chdir(old_cwd)
sys.path.pop(0)
Suppose there something named src
in both sys.path and the cwd,
and that the src
in the system path is not the same src
in the cwd
Did we just import src
from sys.path? or src
from the cwd?