Recall & Review
beginner
What is the
module search path in Python?The module search path is the list of directories Python looks through to find a module when you use
import. It tells Python where to find the files you want to use.Click to reveal answer
beginner
How can you see the current module search path in Python?
You can see it by importing the
sys module and printing sys.path. This shows a list of folders Python checks for modules.Click to reveal answer
beginner
What happens if Python cannot find a module in the search path?
Python raises a
ModuleNotFoundError. This means it looked in all the folders in the search path but did not find the module file.Click to reveal answer
intermediate
How can you add a new folder to the module search path temporarily?
You can add a folder by appending its path to
sys.path in your script. This lets Python look in that folder for modules during that run.Click to reveal answer
beginner
Why is the current working directory usually first in the module search path?
Because Python tries to import modules from your current folder first. This helps you use your own files before looking in system or library folders.Click to reveal answer
What Python list shows the directories where modules are searched?
✗ Incorrect
The
sys.path list contains all directories Python checks for modules.If a module is not found, what error does Python raise?
✗ Incorrect
ModuleNotFoundError is raised when Python cannot find the module in the search path.Which folder is usually checked first when importing a module?
✗ Incorrect
Python checks the current working directory first to find modules.
How can you add a folder to the module search path during a script run?
✗ Incorrect
Appending a folder path to
sys.path adds it temporarily to the search path.What does the
sys.path list include?✗ Incorrect
sys.path is a list of directories Python searches for modules.Explain what the Python module search path is and why it matters when importing modules.
Think about how Python finds the files you want to use.
You got /3 concepts.
Describe how you can check and modify the module search path in a Python script.
Use the sys module to see and change the search path.
You got /3 concepts.