Question 425 of 169
PCAP Modules and Packages Practice Question
A developer has two separate directories on sys.path: /home/user/libs and /opt/libs. Both directories contain a subdirectory 'mypackage' without an __init__.py file. The developer wants to import a module from 'mypackage' that exists only in one of the directories. What concept allows Python to treat these two directories as a single namespace package?
⚠ Common exam trap
Python Institute often tests the distinction between regular packages (with __init__.py) and implicit namespace packages (without __init__.py), and the trap here is that candidates mistakenly think sys.path merging or package overriding is the correct concept, when in fact PEP 420's implicit namespace packages are the precise mechanism that allows multiple directories to form a single package without __init__.py.
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
✓
Implicit namespace packages (PEP 420)
PEP 420 introduced implicit namespace packages, which allow multiple directories on sys.path to contribute to the same package without requiring __init__.py files. When Python encounters a directory without __init__.py, it treats it as a namespace package, merging all matching directories across sys.path into a single logical package. This enables the developer to import a module from 'mypackage' that exists in only one of the directories, as Python searches all paths and resolves the module from the first location where it is found.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Regular packages with __init__.py
Why it's wrong here
Regular packages require an __init__.py file in every directory that is part of the package. With two directories on sys.path that both contain a home folder with __init__.py, Python would treat the first match as the entire package and never combine the contents of the second. This explicit initialization marker makes a regular package a single, monolithic entity, so it cannot represent two separated directories as one package.
- ✗
sys.path merging
Why it's wrong here
sys.path is a sequence of directory strings that Python consults in order when searching for modules and packages, but it contains no mechanism for merging the contents of directories. If two directories both contain a home subdirectory, Python simply continues past a non-matching entry and uses the first entry that resolves the requested attribute; it never unions the two directory trees. Therefore sys.path merging is not a real import feature—it is merely the sequential search order plus name shadowing.
- ✓
Implicit namespace packages (PEP 420)
Why this is correct
PEP 420 introduced implicit namespace packages, which allow a dotted package name to be composed from multiple separate directories on sys.path without requiring __init__.py in any of them. When the import system encounters a directory named home that has no __init__.py, it records that directory as one portion of the package and continues scanning later sys.path entries for additional home directories, assigning the combined list of portions to __path__. This is exactly the mechanism that lets two physically separate directory trees collectively provide the submodules of the package home.
- ✗
Package overriding
Why it's wrong here
The term 'package overriding' does not correspond to any Python import feature; the closest real behavior is shadowing, where an earlier sys.path entry masks a later one rather than combining with it. In a shadowing scenario, if one directory contains a regular package home and another contains a namespace portion, the regular package wins and the second portion is ignored. No built-in facility exists for one package to cleanly replace or override another beyond this search-order precedence.
Visual reference
About these practice questions
Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →
Last reviewed: Jun 30, 2026
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.
Question Discussion
Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.
Sign in to join the discussion.