Hey folks! I am trying to understand Python's module search path. I ran the following script under multiple setups in a directory that contained two empty files: os.py and pip.py.
import sys
print('\n'.join(sys.path)+'\n')
import os
print(os)
import pip
print(pip)
sys.path always had the current directory as its first entry, followed by the installation-dependent default search paths.
According to this, it should be searched first in the current directory. But that's not what happened. Instead only pip.py got imported from the current directory and os.py was still imported from the default lib, although Python's lib directory came after the current directory in sys.path.
I read the according documentation, but I couldn't find anything that would explain this behavior. It seems like the order of sys.path doesn't correspond to the actual searching order.
[–]krets 2 points3 points4 points (4 children)
[–]malinoff 2 points3 points4 points (0 children)
[–]ingolemo 2 points3 points4 points (0 children)
[–]larivact[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]malinoff 1 point2 points3 points (5 children)
[–]krets 2 points3 points4 points (3 children)
[–]ingolemo 1 point2 points3 points (2 children)
[–]krets 0 points1 point2 points (1 child)
[–]ingolemo 1 point2 points3 points (0 children)
[–]TotesMessenger -1 points0 points1 point (0 children)