PCAP Modules and Packages Practice Question
Given package structure: pack/__init__.py, pack/subpack/__init__.py, pack/subpack/mod.py. Inside pack/__init__.py, which import statement correctly imports mod.py using a relative import?
⚠ Common exam trap
Python Institute often tests the distinction between absolute and relative imports, and the trap here is that candidates mistakenly use an absolute import (Option B) or incorrect dot syntax (Option A or C) because they confuse the number of dots or the placement of the module name in the import statement.
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
✓
from .subpack import mod
`from .subpack import mod` uses a leading dot to indicate a relative import from the current package (`pack`), then navigates into `subpack` and imports `mod`. This is the proper syntax for importing a module from a subpackage within the same parent package.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
from . import subpack.mod
Why it's wrong here
When you write `from . import subpack.mod`, Python's import machinery treats the part after `import` as a module name, but it tries to interpret `subpack.mod` as an attribute path, which is not syntactically valid in an import statement. The correct relative import for a submodule is `from .subpack import mod` or `from . import subpack` then access `subpack.mod`, but you cannot combine dot notation after import in that way. Also, the `from . import` form expects a simple name, not a dotted path. So it's a syntax error.
- ✗
from subpack import mod
Why it's wrong here
This is an absolute import, not relative. It refers to a top-level module named `subpack` on `sys.path`, not the `subpack` inside the current package `pack`. In a package context, relative imports are required to ensure the correct module is loaded, especially when there are multiple packages with the same name. Using an absolute import here bypasses the package structure and could import an unrelated module, or fail if `pack` is not on `sys.path` as a parent directory. The question specifically requires a relative import from the current package.
- ✗
from ..subpack import mod
Why it's wrong here
This is a relative import that goes up one level from the current package. The current package is `pack`, so `..` refers to the parent of `pack` (the package containing `pack`). Then `.subpack` would look for a `subpack` subpackage inside that parent, not inside `pack`. This would either fail with an ImportError or import a different module if such a path exists. The correct relative import for a sibling module within the same package is a single dot: `.subpack`.
- ✓
from .subpack import mod
Why this is correct
The leading dot indicates a relative import from the current package (`pack`). This statement imports the `mod` submodule from the `subpack` subpackage that is a child of the current package. This is the standard way to import a module from a sibling subpackage in a package, ensuring the import is resolved relative to the current package's location, not the top-level `sys.path`.
Visual reference
Go deeper
Related to this question
About these practice questions
One of 169 original PCAP practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. 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.