Courseiva
Knowledge + Practice
CertificationsVendorsCareer RoadmapsLabs & ToolsStudy GuidesGlossaryPractice Questions
C
Courseiva

Free IT certification practice questions with explained answers for CCNA, CompTIA, AWS, Azure, Google Cloud, and more.

Certification Practice Questions

CCNA practice questionsSecurity+ SY0-701 practice questionsAWS SAA-C03 practice questionsAZ-104 practice questionsAZ-900 practice questionsCLF-C02 practice questionsA+ Core 1 practice questionsGoogle Cloud ACE practice questionsCySA+ CS0-003 practice questionsNetwork+ N10-009 practice questions
View all certifications →

Product

CertificationsCertification PathsExam TopicsPractice TestsExam Dumps vs Practice TestsStudy HubComparisons

Company

AboutContactEditorial PolicyQuestion Writing PolicyTrust Center

Legal

Privacy PolicyTerms of Service

Courseiva is a free IT certification practice platform offering original exam-style practice questions, detailed explanations, topic-based practice, mock exams, readiness tracking, and study analytics for Cisco, CompTIA, Microsoft, AWS, and other technology certifications.

© 2026 Courseiva. Courseiva is operated by JTNetSolutions Ltd. All rights reserved.

Courseiva is an independent certification practice platform and is not affiliated with, endorsed by, or sponsored by Cisco, Microsoft, AWS, CompTIA, Google, ISC2, ISACA, or any other certification vendor. Vendor names and certification marks are used only to identify the exams learners are preparing for.

← Modules and Packages practice sets

PCAP Modules and Packages • Complete Question Bank

PCAP Modules and Packages — All Questions With Answers

Complete PCAP Modules and Packages question bank — all 0 questions with answers and detailed explanations.

112
Questions
Free
No signup
Certifications/PCAP/Practice Test/Modules and Packages/All Questions
Question 1mediummultiple choice
Read the full Modules and Packages explanation →

A developer is working on a project that requires the use of a third-party package hosted on a private repository. The developer wants to ensure that the package can be imported without specifying the full repository URL each time. Which approach should be taken?

Question 2easymultiple choice
Study the full Python automation breakdown →

A Python script imports the module 'my_module'. The developer wants to ensure that when the script is run directly, it executes a specific function, but when imported as a module, that function is not executed. Which code snippet achieves this?

Question 3hardmultiple choice
Read the full Modules and Packages explanation →

A developer creates a package named 'analytics' with the following structure:

analytics/ __init__.py stats.py models/ __init__.py regression.py

The developer wants the statement 'from analytics import *' to import only the functions 'mean' and 'std' from stats.py. What should be added to analytics/__init__.py?

Question 4mediummultiple choice
Read the full Modules and Packages explanation →

A developer is troubleshooting an ImportError: 'No module named 'config''. The config module is located in a subdirectory 'utils' relative to the script. The script's current working directory is the parent of 'utils'. Which of the following lines, added to the script, will resolve the issue?

Question 5easymultiple choice
Read the full Modules and Packages explanation →

A developer wants to import a specific function 'calculate' from a module named 'formulas' without importing the entire module. Which import statement should be used?

Question 6hardmultiple choice
Study the full Python automation breakdown →

A developer notices that a custom package 'mypackage' is not being found when importing, even though it is installed in the site-packages directory. The developer suspects a conflict with another package of the same name. Which command should the developer run to diagnose the location from which Python is importing the package?

Question 7mediummultiple choice
Read the full Modules and Packages explanation →

A developer is creating a package that contains a subpackage. The subpackage has an __init__.py file that imports a module named 'helper' from the parent package. Which import statement in the subpackage's __init__.py will correctly import 'helper'?

Question 8mediummulti select
Read the full Modules and Packages explanation →

Which TWO of the following are valid ways to import a module named 'math' and give it an alias 'm'?

Question 9hardmulti select
Study the full Python automation breakdown →

Which THREE of the following statements about Python packages and modules are true?

Question 10hardmultiple choice
Study the full Python automation breakdown →

You are a developer at a company that builds a data processing pipeline. The pipeline consists of several Python modules organized in a package called 'pipeline'. The package structure is:

pipeline/ __init__.py load.py transform.py analyze.py

The pipeline is deployed on a server where Python 3.8 is installed. The server also has a globally installed package called 'pipeline' (from a different project) in the site-packages directory. When you run your scripts that import 'pipeline', you get unexpected behavior because Python is importing the wrong package. You need to ensure that your local 'pipeline' package is used instead of the global one. You cannot uninstall the global package because it is used by another application. You have the following options:

A) Modify the PYTHONPATH environment variable to include the directory containing your 'pipeline' package before the site-packages directory. B) Rename your local 'pipeline' package to something else and update all imports. C) Use a virtual environment specific to your project and install your package there. D) Add an __init__.py file with a special import hook to override the global package.

Which course of action is the most appropriate and reliable?

Question 11mediummultiple choice
Study the full Python automation breakdown →

A developer is troubleshooting a Python application that fails to import a custom module named 'utils'. The file 'utils.py' exists in the same directory as the main script. Which of the following is the most likely cause of the import failure?

Question 12hardmultiple choice
Study the full Python automation breakdown →

A Python package 'mypackage' contains the following hierarchy:

mypackage/ __init__.py subpackage1/ __init__.py module_a.py subpackage2/ __init__.py module_b.py

From a script outside the package, a programmer writes:

import mypackage.subpackage1.module_a

Which statement is true about the import?

Question 13easymultiple choice
Read the full Modules and Packages explanation →

A programmer wants to create a package named 'analytics' with subpackages 'statistics' and 'ml'. Which directory structure correctly defines these packages?

Question 14mediummultiple choice
Read the full Modules and Packages explanation →

A developer has a module 'config.py' with the following content:

# config.py
import os

DATABASE_URL = os.getenv('DATABASE_URL', 'localhost')

Another module 'app.py' imports config and uses DATABASE_URL. During testing, the environment variable is set correctly, but the import still uses the default value 'localhost'. What is the most likely reason?

Question 15hardmultiple choice
Study the full Python automation breakdown →

A Python package 'shapes' has the following __init__.py:

# shapes/__init__.py
from .circle import Circle
from .square import Square

A user writes:

import shapes

c = shapes.Circle(5)

This works correctly. However, when the user writes:

import shapes.circle

c = shapes.circle.Circle(5)

It fails with AttributeError: module 'shapes' has no attribute 'circle'. What is the most likely reason?

Question 16mediummulti select
Study the full Python automation breakdown →

Which TWO of the following statements about Python packages are true?

Question 17hardmulti select
Read the full Modules and Packages explanation →

Which THREE of the following are valid ways to import a function named 'calculate' from a module named 'math_ops' located in a subpackage 'operations' of a package 'app'?

Question 18mediummultiple choice
Study the full Python automation breakdown →

You are working on a Python-based data processing pipeline that runs on a Linux server. The pipeline consists of several custom packages and modules located in /opt/mypipeline. The directory structure includes:

/opt/mypipeline/ __init__.py core/ __init__.py processor.py utils/ __init__.py logger.py

The main entry point is /opt/mypipeline/run.py, which imports modules from core and utils. The pipeline is executed using the command:

python /opt/mypipeline/run.py

Recently, the system administrator added a new Python package 'external_lib' to /opt/external_lib, and updated the PYTHONPATH environment variable to include /opt/external_lib. However, after this change, the pipeline fails to start with the following error:

ImportError: cannot import name 'process' from 'core.processor' (unknown location)

You check the PYTHONPATH and find it contains:

/opt/mypipeline:/opt/external_lib

The 'core.processor' module defines a function 'process' that is imported in run.py as:

from core.processor import process

The 'core' package has an __init__.py file. The 'external_lib' package also has a subpackage named 'core' with an __init__.py. What is the most likely cause of the import error?

Question 19mediummultiple choice
Read the full Modules and Packages explanation →

A developer is writing a package that contains multiple modules. The package should allow users to import it directly and have all commonly used functions available at the package level. For example, after `import mypackage`, the user should be able to call `mypackage.func1()` without needing to import submodules. Which is the best way to achieve this?

Question 20hardmulti select
Study the full Python automation breakdown →

Which TWO of the following statements about Python's `sys.path` are true?

Question 21easymultiple choice
Read the full Modules and Packages explanation →

Given the exhibit, why does `dir()` show no names from `mypackage` after executing `from mypackage import *`?

Exhibit

Refer to the exhibit.

```
# file: mypackage/__init__.py
from . import module1
from .module2 import func2
__all__ = ['module1', 'func2']
```

```
# file: mypackage/module2.py
def func2():
    print('func2')
```

```python
>>> from mypackage import *
>>> dir()
['__builtins__', ...]
```
Question 22mediummultiple choice
Study the full Python automation breakdown →

You are developing a Python application that processes financial transactions. The application is structured as a package named `finance`. Inside `finance`, there are subpackages: `models`, `services`, and `utils`. The `services` subpackage contains a module `validator.py` that defines a function `validate_transaction()`. This function uses a helper function `check_amount()` defined in `utils.helpers`. The package is used by multiple other projects, and you want to ensure that importing `finance` does not accidentally expose internal helper functions. You also want to allow users to easily import the main validation function via `from finance import validate_transaction`. Which of the following approaches best achieves these goals?

Question 23mediumdrag order
Study the full Python automation breakdown →

Drag and drop the steps to create and activate a virtual environment in Python into the correct order.

Drag steps to the numbered slots on the right, or tap a step then tap a slot.

Steps
Order
1Step 1
2Step 2
3Step 3
4Step 4
5Step 5
Question 24mediumdrag order
Study the full Python automation breakdown →

Drag and drop the steps to create a simple HTTP server using the http.server module in Python into the correct order.

Drag steps to the numbered slots on the right, or tap a step then tap a slot.

Steps
Order
1Step 1
2Step 2
3Step 3
4Step 4
5Step 5
Question 25mediumdrag order
Study the full Python automation breakdown →

Drag and drop the steps to perform unit testing with the unittest framework in Python into the correct order.

Drag steps to the numbered slots on the right, or tap a step then tap a slot.

Steps
Order
1Step 1
2Step 2
3Step 3
4Step 4
5Step 5
Question 26mediummatching
Study the full Python automation breakdown →

Match each Python built-in function to its description.

Drag a concept onto its matching description — or click a concept then click the description.

Concepts
Matches

Returns the length of an object

Generates a sequence of numbers

Returns a sorted list from an iterable

Returns index and value pairs

Aggregates elements from multiple iterables

Question 27mediummatching
Read the full Modules and Packages explanation →

Match each code snippet to its output.

Drag a concept onto its matching description — or click a concept then click the description.

Concepts
Matches

8

3

1

15

14

Question 28easymultiple choice
Read the full Modules and Packages explanation →

A script is located in the parent directory of a package named 'mypackage'. Which import statement correctly imports the 'foo' module from the 'mypackage' package?

Question 29mediummultiple choice
Study the full Python automation breakdown →

During development, a programmer modifies a module that is already imported in the current Python session. To see the changes without restarting the interpreter, which function from the importlib module should be called?

Question 30hardmultiple choice
Read the full Modules and Packages explanation →

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?

Question 31mediummultiple choice
Study the full Python automation breakdown →

A Python script fails with 'ModuleNotFoundError: No module named 'myapp.config''. The environment variable PYTHONPATH is not set. Which of the following is the most likely cause?

Question 32easymultiple choice
Read the full Modules and Packages explanation →

Which of the following statements about the __init__.py file in a package is true?

Question 33mediummultiple choice
Read the full Modules and Packages explanation →

A team is developing a large application and wants to organize code into packages. Which of the following is a best practice for package design?

Question 34hardmultiple choice
Read the full Modules and Packages explanation →

A developer runs 'pip install mypackage' but gets a 'PermissionError'. Which command should be used to install the package for the current user only?

Question 35mediummultiple choice
Study the full Python automation breakdown →

When importing a module, Python searches for it in a specific order. Which of the following lists the correct order of directories searched?

Question 36easymultiple choice
Read the full Modules and Packages explanation →

Which of the following is a valid way to import a module named 'math' and assign it an alias 'm'?

Question 37mediummulti select
Read the full Modules and Packages explanation →

Which TWO statements about namespace packages are true?

Question 38hardmulti select
Read the full Modules and Packages explanation →

Which THREE factors can cause an 'ImportError' when trying to import a module?

Question 39easymulti select
Read the full Modules and Packages explanation →

Which TWO of the following are valid ways to import specific names from a module?

Question 40mediummultiple choice
Read the full Modules and Packages explanation →

Refer to the exhibit. A script executes 'from mypackage import *'. Which functions are available in the global namespace?

Exhibit

Exhibit:
# file: mypackage/__init__.py
__all__ = ["module_a", "module_b"]
# file: mypackage/module_a.py
def func(): pass
# file: mypackage/module_b.py
def func(): pass
Question 41mediummultiple choice
Read the full Modules and Packages explanation →

Refer to the exhibit. A developer runs 'pip install pandas==2.0.0' but gets an error stating that the required version is not available. Which command should be used to list all available versions of pandas?

Exhibit

Exhibit:
$ pip list
Package    Version
---------- -------
numpy      1.24.0
pandas     1.5.3
pip        22.0.4
Question 42mediummultiple choice
Read the full Modules and Packages explanation →

Refer to the exhibit. Given the project structure, which of the following import statements in main.py would cause an ImportError?

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 bold
Question 43mediummultiple choice
Read the full Modules and Packages explanation →

A developer has a project structure with 'my_package/' containing '__init__.py', 'module_a.py', and 'sub_package/' (with its own '__init__.py'). They want to import function 'foo' from 'module_a' inside a script in 'sub_package' using a relative import. Which statement is correct?

Question 44easymultiple choice
Study the full Python automation breakdown →

A Python script uses a third-party library 'requests'. The developer wants to ensure that the exact version 2.25.1 is installed in the project's environment. Which tool and command should be used?

Question 45hardmultiple choice
Study the full Python automation breakdown →

A developer is creating a Python package named 'utils' and wants to control what is imported when a user writes 'from utils import *'. Which file and variable should be defined?

Question 46mediummultiple choice
Study the full Python automation breakdown →

A Python application needs to load a configuration file that should be placed in the same directory as the main script. The developer uses the __file__ attribute to get the script's path. Which expression correctly obtains the directory containing the main script?

Question 47easymultiple choice
Study the full Python automation breakdown →

A team is using a shared Python environment where multiple projects have conflicting dependencies. Which approach is the best practice to isolate project dependencies?

Question 48hardmultiple choice
Read the full Modules and Packages explanation →

A package 'mypkg' has the following structure: mypkg/ __init__.py submod1.py submod2.py The __init__.py file contains: from . import submod1, submod2. A user runs 'import mypkg' and then 'mypkg.submod1.func()'. However, the user got an AttributeError. What is the most likely cause?

Question 49easymultiple choice
Read the full NAT/PAT explanation →

A developer wants to use a function 'calculate' from a module 'math_ops' that is located in a sibling directory '../shared/' relative to the current script. What is the correct way to import it using an absolute import assuming the shared directory is a package with __init__.py and the project root is in sys.path?

Question 50mediummultiple choice
Study the full Python automation breakdown →

A Python package 'analytics' contains a subpackage 'models' with module 'regression.py'. Inside 'regression.py', there is a function 'linear_fit' that depends on 'numpy'. The developer wants to ensure that 'numpy' is imported only once and available throughout the package. Where should the import 'import numpy as np' be placed?

Question 51hardmultiple choice
Read the full NAT/PAT explanation →

A developer runs the following code in a script that is not part of a package:

import sys

sys.path.insert(0, '/custom/path')

import mymodule
print(mymodule.__name__)

What is the output if 'mymodule' is found at '/custom/path/mymodule.py'?

Question 52mediummulti select
Read the full Modules and Packages explanation →

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

Question 53hardmulti select
Study the full Python automation breakdown →

Which THREE of the following statements about Python's module search path are true?

Question 54easymulti select
Study the full Python automation breakdown →

Which TWO of the following are valid uses for the '__name__' variable in a Python module?

Question 55mediummultiple choice
Study the full Python automation breakdown →

A Python script placed in /opt/myapp/script.py fails with ImportError when run from a cron job with the command: python /opt/myapp/script.py. The script works when run manually from the /opt/myapp/ directory. The script contains the line: from . import config. The config module is located in /opt/myapp/lib/config.py with an __init__.py in /opt/myapp/lib/. What is the most likely cause of the failure?

Question 56hardmultiple choice
Read the full Modules and Packages explanation →

A package 'mypackage' has subpackages 'sub1' and 'sub2'. In sub1/__init__.py, there is: from sub2 import helper. When importing mypackage, an ImportError occurs: No module named 'sub2'. What is the most likely cause?

Question 57easymultiple choice
Read the full Modules and Packages explanation →

A programmer wants to use the sqrt function from the math module. Which import statement is most efficient?

Question 58mediummultiple choice
Read the full Modules and Packages explanation →

A team uses virtual environments to manage dependencies. They need to ensure that a script runs with the exact same module versions across different environments. Which approach is best?

Question 59hardmultiple choice
Read the full NAT/PAT explanation →

A developer appends a custom path to sys.path and then tries to import a function from a module: import sys; sys.path.append('/custom/libs'); from mylib import func. The import fails with ModuleNotFoundError. mylib is a directory. What is the most likely cause?

Question 60easymultiple choice
Read the full Modules and Packages explanation →

A module 'config.py' contains a variable 'settings' that is a dictionary. Another script does: from config import settings. Then the script modifies settings['key'] = 'new_value'. What happens?

Question 61mediummultiple choice
Read the full Modules and Packages explanation →

A package 'tools' has the structure: tools/__init__.py, tools/calc.py, tools/io.py. In __init__.py, the developer writes: from . import calc. A user tries: import tools; print(tools.add(1,2)). This fails with AttributeError. Why?

Question 62hardmultiple choice
Read the full NAT/PAT explanation →

A script runs: import sys; print(sys.path[0]). The output is an empty string. What does this indicate?

Question 63easymultiple choice
Read the full Modules and Packages explanation →

A developer runs pip install requests. Later, they need to find out where the module is installed on the system. Which command shows the location?

Question 64easymulti select
Read the full Modules and Packages explanation →

Which TWO of the following are valid ways to import a function named 'func' from a module 'mymod' that is in the same directory as the script?

Question 65mediummulti select
Read the full Modules and Packages explanation →

Which THREE of the following are true about the __pycache__ directory?

Question 66hardmulti select
Read the full Modules and Packages explanation →

Which TWO of the following are true about importing modules using the import statement?

Question 67easymultiple choice
Read the full Modules and Packages explanation →

A user runs script.py and gets the above error. Which of the following is the most likely cause?

Exhibit

Traceback (most recent call last):
  File "script.py", line 1, in <module>
    from mypackage import myfunction
ModuleNotFoundError: No module named 'mypackage'
Question 68mediummultiple choice
Read the full Modules and Packages explanation →

A developer runs pip install package==1.0 and gets the above error. What is the most likely solution?

Exhibit

ERROR: Could not find a version that satisfies the requirement package==1.0 (from versions: 2.0, 2.1)
ERROR: No matching distribution found for package==1.0
Question 69hardmultiple choice
Read the full Modules and Packages explanation →

In module_b.py, the developer writes: from mypackage import module_a. When running a script that imports mypackage, an ImportError occurs. Which change should solve the issue?

Exhibit

Consider the following package structure:
mypackage/
    __init__.py
    module_a.py
    subpackage/
        __init__.py
        module_b.py
Question 70easymultiple choice
Study the full Python automation breakdown →

A developer needs to add a custom directory '/home/user/mylibs' to Python's module search path so that modules in that directory can be imported. Which code snippet accomplishes this correctly?

Question 71easymultiple choice
Read the full Modules and Packages explanation →

A package named 'utilities' contains a submodule 'strings'. Which import statement allows the use of the function 'reverse' defined in utilities.strings as reverse() without needing to prefix it?

Question 72easymultiple choice
Study the full Python automation breakdown →

A Python script is written to be used both as a standalone program and as an imported module. Which condition should the script use to execute code only when run directly?

Question 73mediummultiple choice
Read the full Modules and Packages explanation →

Two modules, 'module_a' and 'module_b', import each other. When 'module_a' is imported first, it tries to import 'module_b', which in turn tries to import 'module_a' again, causing a circular import error. Which of the following is the most effective strategy to resolve this circular dependency?

Question 74mediummultiple choice
Read the full Modules and Packages explanation →

A package 'shapes' has an __init__.py file. Which statement must be included in the __init__.py file to allow the syntax 'from shapes import *' to import all submodules 'circle', 'square', and 'triangle'?

Question 75mediummultiple choice
Read the full Modules and Packages explanation →

Inside a package 'data', there is a subpackage 'io' and a module 'utils'. Which import statement inside the 'io' subpackage correctly imports the 'helper' function from the sibling module 'utils'?

Question 76hardmultiple choice
Study the full Python automation breakdown →

A developer has two separate directories on sys.path: /home/user/libs and /opt/libs. Both directories contain a subdirectory 'mypackage' without an __init__.py file. The developer wants to import a module from 'mypackage' that exists only in one of the directories. What concept allows Python to treat these two directories as a single namespace package?

Question 77hardmultiple choice
Read the full Modules and Packages explanation →

An application needs to dynamically load a module whose name is provided at runtime (stored in a variable 'mod_name'). Which function from the importlib module should be used?

Question 78hardmultiple choice
Read the full NAT/PAT explanation →

A user wants to ensure that a custom module 'mymod' located at '/home/user/custom' takes precedence over a standard library module with the same name. Which operation on sys.path should be performed?

Question 79easymulti select
Study the full Python automation breakdown →

Which TWO of the following are valid ways to import a module 'math' in Python?

Question 80mediummulti select
Read the full Modules and Packages explanation →

Which TWO statements about the sys module are true?

Question 81hardmulti select
Study the full Python automation breakdown →

Which THREE of the following are recommended techniques to avoid circular imports in Python?

Question 82easymultiple choice
Read the full Modules and Packages explanation →

Refer to the exhibit. Which import statement in app.py will successfully import and use the greet function from helpers.py?

Exhibit

my_project/
    __init__.py
    app.py
    utils/
        __init__.py
        helpers.py (contains def greet(): pass)
Question 83mediummultiple choice
Read the full Modules and Packages explanation →

Refer to the exhibit. Which of the following is the most likely cause of this error?

Exhibit

Traceback (most recent call last):
  File "main.py", line 1, in <module>
    from mypackage import mymodule
ImportError: cannot import name 'mymodule' from 'mypackage' (unknown location)
Question 84hardmultiple choice
Study the full Python automation breakdown →

Refer to the exhibit. A Python script uses the following code to load the policy. However, it fails with a JSONDecodeError. What is the most likely cause? ```python

import json
with open('policy.json', 'r') as f:

policy = json.load(f) ```

Exhibit

{
  "rules": [
    {"action": "allow", "src": "10.0.1.0/24"},
    {"action": "deny", "src": "0.0.0.0/0"},
  ]
}
Question 85easymultiple choice
Read the full Modules and Packages explanation →

A developer creates a package named 'mypkg' with an __init__.py file. Inside the package, there is a module 'utils.py'. Which of the following is the correct way to import the function 'helper' from 'utils' from outside the package?

Question 86mediummultiple choice
Study the full Python automation breakdown →

A team is developing a large Python application with multiple modules. They encounter an ImportError when module A tries to import from module B, and module B tries to import from module A. What is the most likely cause and best practice to resolve this?

Question 87hardmultiple choice
Study the full Python automation breakdown →

A Python project has the following directory structure:

project/ __init__.py main.py subpackage/ __init__.py module.py

Inside 'module.py', there is a function 'func' that needs to be imported in 'main.py'. The team wants to import 'func' using a relative import from 'main.py'. However, when they run 'python main.py' from the project root, they get an ImportError. What is the most likely reason?

Question 88mediummultiple choice
Study the full Python automation breakdown →

A developer installs a third-party package using pip, but when they try to import it in their script, Python raises a ModuleNotFoundError. The package is definitely installed (pip list shows it). What is the most likely cause?

Question 89easymultiple choice
Read the full Modules and Packages explanation →

A module 'shapes.py' defines several classes: Circle, Square, Triangle. The developer wants to allow users to import only Circle and Square when they use 'from shapes import *'. Which mechanism should be used?

Question 90hardmultiple choice
Study the full Python automation breakdown →

A Python project uses namespace packages spread across multiple directories. The package structure is: project/ and lib/ both contain subdirectories 'mypkg/'. Each has an __init__.py file. When importing 'mypkg', which directory's contents are used?

Question 91mediummultiple choice
Study the full Python automation breakdown →

A company has a shared internal library stored in a Git repository. Developers need to use this library in multiple projects without copying the code. Which approach is the most Pythonic and maintainable?

Question 92easymultiple choice
Study the full Python automation breakdown →

A developer wants to distribute a package that contains both Python code and data files (e.g., images, configs). Which file is used to specify dependencies and metadata for the package?

Question 93hardmultiple choice
Read the full Modules and Packages explanation →

A package 'pkg' is installed as an egg-link in development mode. Inside the package, there is a module 'submod.py' that uses relative imports. When a developer modifies 'submod.py', they find that changes are not always reflected on import. What is the most likely reason?

Question 94mediummulti select
Study the full Python automation breakdown →

Which TWO statements about the __init__.py file in a Python package are true?

Question 95hardmulti select
Study the full Python automation breakdown →

Which THREE factors influence Python's module search path (sys.path)?

Question 96mediummulti select
Read the full Modules and Packages explanation →

Which TWO methods are valid ways to import a function named 'foo' from a module 'bar' that is part of a package 'pkg'?

Question 97mediummultiple choice
Study the full Python automation breakdown →

You are a Python developer working on a project with the following structure:

myapp/ __init__.py main.py modules/ __init__.py utils.py helpers.py

The file main.py contains:

from modules import utils
from modules import helpers

utils.some_function() helpers.another_function()

When you run main.py, you get an ImportError: No module named 'modules'. However, the modules directory exists and both __init__.py files are present. The directory myapp is not installed as a package; you are running main.py directly from the myapp directory. What is the most likely cause and how should you fix it?

Question 98hardmultiple choice
Study the full Python automation breakdown →

You are a DevOps engineer managing a Python application that consists of multiple microservices. One microservice, 'data_processor', imports a shared library 'common_lib' which is also used by other microservices. The shared library is developed in a separate repository and is installed via pip in each microservice's virtual environment as an editable package (pip install -e). Recently, you updated 'common_lib' with new functions, but when you redeploy 'data_processor' (by restarting the container), the new functions are not available; the old version is still used. The container uses a Docker image built from a requirements file that specifies 'common_lib' from a Git repository. You verify that the Git commit hash in the requirements file points to the latest version. What is the most likely cause and what is the correct course of action?

Question 99mediummultiple choice
Read the full Modules and Packages explanation →

You are developing a package 'analytics' that contains subpackages 'stats' and 'ml'. The __init__.py of 'analytics' imports a function 'normalize' from 'analytics.stats'. When a user runs `import analytics`, they get an ImportError. Which change ensures the package imports correctly?

Question 100hardmultiple choice
Read the full Modules and Packages explanation →

A team maintains a library 'utils' with multiple modules. They want to expose a clean public API so that users can do `from utils import helper`. However, they also have internal modules that should not be accessible directly. Which approach best achieves this?

Question 101easymulti select
Study the full Python automation breakdown →

Which TWO statements about the __init__.py file in a Python package are true?

Question 102mediummulti select
Read the full Modules and Packages explanation →

Consider the following directory structure: project/ main.py pkg/ __init__.py mod1.py subpkg/ __init__.py mod2.py From main.py, you write: from pkg.subpkg import mod2 Which THREE of the following are true regarding relative imports?

Question 103hardmultiple choice
Read the full NAT/PAT explanation →

You are a developer for a data science team. The team uses a shared module 'utilities' located at /team/shared/utilities.py. This module is not part of any package, and they want to import it from various project scripts without copying the file. Some projects are in /home/user/proj_A/ and others in /var/data/proj_B/. Currently, each script manually adds /team/shared/ to sys.path using sys.path.insert(0, '/team/shared/'). This works but is repetitive. The team wants a cleaner solution that also works when the script is run from different working directories. They consider creating a package 'utilities' by adding an __init__.py to the directory and using relative imports. However, the module currently uses absolute imports for some external libraries. What is the best course of action to allow clean imports of utilities from any location while minimizing changes to the module itself?

Question 104mediummultiple choice
Study the full Python automation breakdown →

Your company has two separate Python packages: 'app' and 'lib'. They are maintained by different teams. 'app' depends on 'lib', but 'lib' is still under development and its API changes frequently. To avoid breaking 'app', the team decides to use a virtual environment and install a specific version of 'lib'. However, during development, they need to test 'app' with the latest 'lib' changes from the Git repository. The current workflow is: (1) activate virtual env, (2) install 'lib' from local source using `pip install -e /path/to/lib`. This installs 'lib' as a development package. But one developer reports that after pulling latest 'lib' changes, importing 'lib' in 'app' still uses the old version even after re-running pip install -e. What is the most likely reason?

Question 105hardmultiple choice
Study the full Python automation breakdown →

A company has a large Python application that uses multiple packages from different directories. The application's main entry point is at /opt/app/main.py. There is a package 'common' located at /opt/app/common/ and another package 'services' at /opt/app/services/. Both packages have __init__.py files. Additionally, there is a third-party package 'utils' installed in the system site-packages. Recently, a developer added a new module 'helpers.py' to the 'common' package. When trying to import 'common.helpers' from a script inside 'services', an ImportError is raised: 'No module named common.helpers'. However, importing 'common' itself works. The sys.path includes /opt/app/ and the site-packages. What is the most likely cause of the import failure?

Question 106easymultiple choice
Study the full Python automation breakdown →

You are working on a Python project that uses multiple third-party packages. One of your scripts imports 'requests' and 'numpy'. You notice that when you run your script, it uses the system-wide installed versions, but you want to use versions installed in a virtual environment. You have already activated the virtual environment using `source venv/bin/activate`, and `which python` points to the virtual environment's Python. However, when you import 'requests', it still uses the global version. What is the most likely reason?

Question 107mediummultiple choice
Read the full Modules and Packages explanation →

A developer creates a package 'mypackage' with the following structure:

mypackage/ __init__.py module1.py module2.py

The __init__.py contains:

from mypackage.module1 import func1
from mypackage.module2 import func2

__all__ = ['func1', 'func2']

In a separate script, the developer writes:

from mypackage import *
print(func1())

This works as expected. However, when the developer runs the same script from a different directory (not the one containing mypackage), the import works but the script prints an error that func1 is not defined. What could be the problem?

Question 108mediummultiple choice
Study the full Python automation breakdown →

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?

Question 109easymultiple choice
Study the full Python automation breakdown →

Your team is developing a large application with many packages. To avoid name conflicts, you decide to use namespace packages. You have two directories: /team/common/ and /team/analytics/. Both contain an __init__.py file. You want to create a namespace package 'team' that combines these two directories. You create a directory /team/ with no __init__.py. You then set PYTHONPATH to /team/common/ and /team/analytics/ (actually, you set it to the parent directories). But when you try to `from team.common import something`, you get ModuleNotFoundError. What is the most likely reason?

Question 110easymulti select
Read the full Modules and Packages explanation →

Which TWO statements about the 'from package import *' statement are correct?

Question 111mediummultiple choice
Read the full Modules and Packages explanation →

What is the most likely cause of this error?

Exhibit

Refer to the exhibit.
```
# package/__init__.py
from . import submodule

# package/submodule.py
from . import __init__

# main.py
import package
```
Error:
```
ImportError: cannot import name '__init__' from partially initialized module 'package' (most likely due to a circular import)
```
Question 112hardmultiple choice
Read the full NAT/PAT explanation →

A team is developing a large application that consists of multiple components, each housed in separate directories. They want to organize these components under a common namespace package called 'app'. The directory structure is as follows:

/opt/project/ ├── components/ │ ├── auth/ (contains __init__.py and modules) │ └── billing/ (contains __init__.py and modules) ├── main.py └── another_location/ └── reports/ (contains __init__.py and modules)

The team wants to allow all these components to be imported as subpackages of 'app', e.g., 'import app.auth', 'import app.billing', 'import app.reports'. They have ensured that none of the directories named 'app' exist; instead, they plan to use namespace packages. They create a directory '/opt/project/app/' with an __init__.py file, and move the auth and billing directories under it. However, the reports directory must remain at '/opt/project/another_location/reports/', but they want it to be accessible as 'app.reports'. They attempt to achieve this by adding '/opt/project/another_location/' to the sys.path. When they run main.py, they get an ImportError: No module named 'app.reports'. The auth and billing modules work fine. What is the most likely issue and the correct fix?

Practice tests

Scored 10-question sessions with instant feedback and explanations.

PCAP Practice Test 1 — 10 Questions→PCAP Practice Test 2 — 10 Questions→PCAP Practice Test 3 — 10 Questions→PCAP Practice Test 4 — 10 Questions→PCAP Practice Test 5 — 10 Questions→PCAP Practice Exam 1 — 20 Questions→PCAP Practice Exam 2 — 20 Questions→PCAP Practice Exam 3 — 20 Questions→PCAP Practice Exam 4 — 20 Questions→Free PCAP Practice Test 1 — 30 Questions→Free PCAP Practice Test 2 — 30 Questions→Free PCAP Practice Test 3 — 30 Questions→PCAP Practice Questions 1 — 50 Questions→PCAP Practice Questions 2 — 50 Questions→PCAP Exam Simulation 1 — 100 Questions→

Practice by domain

Each domain maps to a weighted exam section. Focus on the domain where you are weakest.

Modules and PackagesStringsObject-Oriented ProgrammingExceptions and File I/O

Practice by scenario

Filter questions by type — troubleshooting, exhibit, drag-and-drop, PBQ, ACLs, OSPF, and more.

Browse scenarios→

Continue studying

All Modules and Packages setsAll Modules and Packages questionsPCAP Practice Hub