Inspect sys.path

Easysys Module Programs · 9 of 20

Write a Python program that shows how many folders Python searches for modules.

Advertisement
Output
list True
True

Approach

  1. sys.path is a list of folder names.

Solution

Python
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.

More sys module programs

← All 20 sys Module Programs

Leave a Comment