0
0
Pythonprogramming~5 mins

Module search path in Python - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Asys.path
Bos.environ
Csys.modules
Dimport.path
If a module is not found, what error does Python raise?
AFileNotFoundError
BModuleNotFoundError
CImportError
DNameError
Which folder is usually checked first when importing a module?
ASystem library folder
BUser home directory
CCurrent working directory
DTemporary files folder
How can you add a folder to the module search path during a script run?
AAppend the folder path to sys.path
BSet PYTHONPATH environment variable inside the script
CUse importlib.add_path()
DCreate a new module named sys.path
What does the sys.path list include?
AEnvironment variables
BList of all imported modules
CPython version information
DDirectories where Python looks 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.