Python Practice › sys Module Programs › Program 9
Inspect sys.path
Write a Python program that shows how many folders Python searches for modules.
Output
list True True
Approach
sys.pathis a list of folder names.
Solution
import sys print(type(sys.path).__name__, len(sys.path) > 0)print(any("site-packages" in p for p in sys.path))Output
list True True
Note
The real folder names include your user name on most computers, so the program prints checks instead of the list.
Learn the concept
New to this topic? Read the lesson, then come back.