Courseiva
Modules and PackagesmediumMultiple SelectObjective-mapped

PCAP Modules and Packages Practice Question

Which TWO of the following are valid ways to import a function 'foo' from a module 'bar' that is located in a package 'mypackage'?

⚠ Common exam trap

Python Institute often tests the distinction between importing a module versus importing an attribute from a module, and the trap here is that candidates mistakenly think `from mypackage import bar.foo` is valid because they confuse it with the valid `from mypackage.bar import foo` syntax.

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 mypackage.bar import foo

The syntax `from mypackage.bar import foo` directly imports the function `foo` from the module `bar` within the package `mypackage`. This is the standard Python import statement for importing a specific attribute from a submodule.

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 mypackage import bar.foo

    Why it's wrong here

    Invalid syntax; cannot use dot after import.

  • from mypackage.bar import foo

    Why this is correct

    Correct absolute import.

  • import mypackage.bar; then use bar.foo

    Why this is correct

    Import the module, then access the function via module attribute.

  • from . import bar.foo

    Why it's wrong here

    Invalid syntax; should be 'from .bar import foo'.

  • import mypackage.bar.foo

    Why it's wrong here

    Importing a function directly with import statement is invalid; only modules/packages.

Visual reference

Client Server SYN (seq=100) SYN-ACK (seq=200, ack=101) ACK (ack=201) Connection established — data transfer begins

About these practice questions

Courseiva writes every PCAP question from scratch — 169 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 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.