PCAP Modules and Packages Practice Question
Exhibit
Exhibit:
Project structure:
main.py
utils/
__init__.py
helpers.py
strings/
__init__.py
format.py
# main.py
from utils.helpers import greet
from utils.strings.format import boldRefer to the exhibit. Given the project structure, which of the following import statements in main.py would cause an ImportError?
⚠ Common exam trap
Python Institute often tests the distinction between absolute and relative imports, trapping candidates who assume that '..' works in any script, when in fact relative imports are only valid inside a package and fail with an ImportError when used in a top-level script.
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 ..utils import helpers
Uses a relative import with '..' which is only valid inside a package (i.e., when the module is loaded as part of a package and has a __package__ attribute set). In a flat project structure where main.py is a top-level script, '..' attempts to go above the top-level package, which is not allowed and raises an ImportError. Python's import system requires that relative imports be used only within a package hierarchy.
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 utils import strings
Why it's wrong here
This is a normal absolute import, not the one that triggers an ImportError. When main.py is executed from the project root, the root directory is on sys.path, so utils is a top-level package and from utils import strings correctly binds the utils.strings subpackage to the name strings. Because the statement runs without error, it is a valid program line and therefore cannot be the correct answer to a question about an invalid import.
- ✓
from ..utils import helpers
Why this is correct
The leading double dot in from ..utils import helpers marks this as a relative import that climbs one level above the current package. If this line appears in main.py at the project root, main.py is being executed as the __main__ module rather than as an importable package member, so its __package__ is empty and there is no parent package to resolve the dots. This raises ImportError: attempted relative import with no known parent package, which is exactly why this is the only statement that fails and the correct answer.
- ✗
from utils import helpers
Why it's wrong here
Although it resembles the correct option, this line is an absolute import, not a relative one. Since utils is a package directory containing __init__.py, and the project root is on sys.path when main.py is run, Python resolves utils as a top-level package and imports the helpers submodule without any issue. This valid absolute import succeeds, so it is a wrong answer choice for a question about an import that will fail.
- ✗
from utils.strings import format
Why it's wrong here
This statement uses an absolute dotted-path import that descends into the utils package and then into the utils.strings subpackage. As long as utils.strings is an importable subpackage with its own __init__.py (or a module object), from utils.strings import format resolves the format attribute or submodule correctly and binds it as a local name. It executes without raising the relative-import error, so this option is not the requested invalid import and is marked wrong.
Go deeper
Related to this question
About these practice questions
This PCAP question is part of Courseiva's 169-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.