Courseiva
Computer Programming and Python FundamentalshardMultiple ChoiceObjective-mapped

PCEP Computer Programming and Python Fundamentals Practice Question

A company has a Python script that imports a module from a package. The package structure is: mypackage/__init__.py, mypackage/module.py. The script uses 'from mypackage import module'. Which file must exist for this import to work?

⚠ Common exam trap

The PCEP exam often tests the misconception that only the module file itself is needed, ignoring the requirement of __init__.py to designate a directory as a package, especially since Python 3.3+ introduced implicit namespace packages which can confuse candidates.

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

mypackage/__init__.py

For a Python import like 'from mypackage import module' to work, the directory 'mypackage' must be recognized as a package. This requires the presence of an __init__.py file inside it (even if empty), which signals to Python that the directory is a package and allows its submodules to be imported. Option B is correct because __init__.py is the file that makes 'mypackage' a 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.

  • mypackage.py

    Why it's wrong here

    That would be a module, not a package.

  • mypackage/__init__.py

    Why this is correct

    This file marks the directory as a Python package.

  • module.py in the current directory

    Why it's wrong here

    The import uses the package hierarchy, not the current directory.

  • Only mypackage/module.py is needed

    Why it's wrong here

    Without __init__.py, Python does not recognize mypackage as a package (unless using namespace packages).

About these practice questions

Courseiva writes every PCEP question from scratch — 498 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This PCEP 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 PCEP exam.