Courseiva
Modules and PackagesmediumMultiple ChoiceObjective-mapped

PCAP Modules and Packages Practice Question

You maintain a Python library 'myutils' that is installed as a package in the system. The library has a submodule 'config' that reads configuration from a file. Recently, a user reported that after updating the library, their application still uses the old configuration values. They confirmed that the config file on disk has been updated. The library's __init__.py does: from .config import load_config. The user's application imports load_config from myutils and calls it each time they need configuration. What is the most likely cause of the issue?

⚠ Common exam trap

Python Institute often tests the misconception that Python always recompiles .pyc files when the source changes, but the trap is that Python relies on file timestamps, not content hashes, so a stale .pyc can persist if the .py timestamp is not updated during installation.

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

The library's .pyc files were not regenerated because the .py timestamps were not updated during the install, so Python used the cached bytecode from the previous version.

Python caches compiled bytecode in .pyc files. If the .pyc file's timestamp is newer than the corresponding .py file, Python will use the cached bytecode without recompiling. During a package update, if the .py files' timestamps are not updated (e.g., due to a flawed installation process), Python continues to load the old .pyc, causing the old configuration-reading code to execute even though the config file on disk has changed.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • The user did not restart the Python interpreter, so sys.modules still contains the old module.

    Why it's wrong here

    This explanation fails because the problem statement explicitly says the user restarted the application. On a fresh interpreter start, sys.modules is rebuilt from scratch, so any modules imported in the previous run are gone; there is no persistent sys.modules across processes. The stale-code symptom therefore cannot be attributed to an interpreter that was never terminated, because the restarted Python process would not retain old module objects.

  • The import statement in __init__.py is cached, so the module is not reloaded even after update.

    Why it's wrong here

    The import statement in __init__.py is not cached by Python in any persistent sense; every import of the package re-executes that statement within the new process. What can persist across installations, however, is a stale .pyc file on disk: the import system may re-use cached bytecode if the source file's timestamp looks unchanged. Thus the statement itself always runs, but it loads bytecode that may predate the updated source, which is the real reason the new code does not appear.

  • The library's .pyc files were not regenerated because the .py timestamps were not updated during the install, so Python used the cached bytecode from the previous version.

    Why this is correct

    Python's import machinery validates cached bytecode by comparing the source file's modification time (and often size) with the values stored in the .pyc header. If an installer copies only the .py files without updating their mtimes—for example, by preserving timestamps from the build or using a tool that does not touch the destination files—the old .pyc still appears to match the unchanged source timestamp. Python then loads the stale bytecode instead of recompiling, so even though the .py file on disk contains the new code, the interpreter executes the previous version.

  • The config module caches the configuration file contents in memory after the first read.

    Why it's wrong here

    An in-memory cache inside a config module would only matter after the new module code is actually executed; it cannot explain why the freshly restarted Python process still runs old library code. If the library's .py files were modified but the old .pyc was used, the config module itself was never re-imported from the new source. This option incorrectly shifts the cause from the bytecode caching layer to application-level memoization, which is both unrelated and unsupported by the symptom of a library update not taking effect.

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 →

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.