PCAP Modules and Packages Practice Question
When importing a module, Python searches for it in a specific order. Which of the following lists the correct order of directories searched?
⚠ Common exam trap
Python Institute often tests the misconception that PYTHONPATH is searched before the current directory, or that sys.path is a static list rather than a dynamically built sequence starting with the script's directory.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
[current directory] then PYTHONPATH then site-packages
When Python imports a module, it first searches the directory containing the input script (or current working directory), then iterates through the directories listed in the PYTHONPATH environment variable, and finally checks installation-dependent default paths such as site-packages. This order is reflected in sys.path, which is built from the script directory, PYTHONPATH entries, and default site-packages. Option B accurately lists this sequence: current directory, then PYTHONPATH, then site-packages.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
PYTHONPATH then sys.path
Why it's wrong here
This option misidentifies the search order because PYTHONPATH is not a separate path searched before sys.path; rather, its entries are inserted directly into sys.path after the script's directory. At startup, Python sets sys.path[0] to the directory containing the script, then prepends the directories listed in PYTHONPATH to the remaining sys.path entries, which already include standard library and site-packages. Thus the actual lookup sequence is script-directory, then PYTHONPATH entries, then the rest of sys.path—not simply 'PYTHONPATH then sys.path'.
- ✓
[current directory] then PYTHONPATH then site-packages
Why this is correct
This option incorrectly treats current directory, PYTHONPATH, and site-packages as three distinct search locations, whereas all are simply elements of the single sys.path list. The current directory (specifically the script's directory) is placed at sys.path[0], and PYTHONPATH directories are added immediately after it, while site-packages appears later, but the interpreter never performs separate 'phases' for these; it linearly walks the combined sys.path list. Moreover, the phrase 'current directory' is imprecise because Python uses the script's directory for file execution, not the process's current working directory.
- ✗
sys.path + [current directory]
Why it's wrong here
This option reverses the actual placement of the current directory in sys.path. When a script is executed, Python inserts the directory containing that script at sys.path[0], so it is searched first, not last. Appending the current directory to the end of sys.path would mean local modules would only be found after searching all other paths, which contradicts Python's documented behavior of giving the script's directory highest priority. The correct representation is '[current directory] + sys.path', where sys.path already contains PYTHONPATH entries and standard library paths.
- ✗
[current directory] + sys.path
Why it's wrong here
This is correct because Python builds sys.path by placing the directory containing the executed script at index 0, then appending the remaining entries derived from PYTHONPATH, the standard library, and site-packages. During an import, the interpreter iterates through sys.path in order, so the script's directory is examined first, giving local modules precedence over installed packages. This ordering ensures that a module in the same directory as the script can be imported without relying on the process's current working directory or on PYTHONPATH being set.
Go deeper
Related to this question
About these practice questions
This PCAP question is part of Courseiva's 421-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This PCAP practice question is part of Courseiva's free Python Institute certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCAP exam.