Courseiva

PCPP1 · domain

Library Modules

The Library Modules domain of PCPP1 checks applied fluency with Python's standard library beyond the basics: csv dialect control, xml.dom.minidom attribute access, shutil tree copying with metadata and failure semantics, and tkinter event loops with long-running work. Questions are scenario-based, asking you to pick the correct call, argument, or pattern rather than recite documentation.

48 questions9 easy24 medium15 hard

Focused practice

Practice Library Modules questions

Scored sessions drawing only from this domain — pick a length below.

Start 20-question practice test →

What this domain covers

What to know about Library Modules

You must be able to configure csv dialects, read xml.dom.minidom attributes correctly, copy directory trees with shutil while preserving metadata and controlling overwrite behavior, and keep tkinter windows animated during long work. The key skill is choosing the exact argument or method that matches the required behavior.

Configuring csv readers and writers with delimiter, quotechar, and dialect parameters for non-comma formats

Retrieving element attribute values via xml.dom.minidom getAttribute and related node methods

Using shutil.copytree with copy_function, dirs_exist_ok, and metadata-preserving copy2 behavior

Keeping tkinter responsive during long tasks using after, update, or worker threads instead of blocking mainloop

Watch out for

Common Library Modules exam traps

  • ▸Assuming csv.reader auto-detects delimiters; you must pass delimiter=';' or a registered dialect explicitly
  • ▸Confusing getAttribute with getElementsByTagName or childNodes when reading a specific attribute value from a DOM element
  • ▸Letting shutil.copytree silently merge into an existing destination by forgetting dirs_exist_ok, or losing metadata by using copy instead of copy2

Question index

All Library Modules questions (48)

Click any question to see the full explanation, or start a practice session above.

1

You are using the logging module in a long-running service. You need to ensure that a specific logger named 'app.db' writes DEBUG and higher messages to a file, but its parent logger 'app' must not propagate these DEBUG messages to the root logger. Which configuration achieves this?

Hard
2

What is the purpose of the logging.StreamHandler?

Easy
3

You are developing a Python application that must parse a large XML file and extract specific data. The file is too large to fit into memory, so you need to process it incrementally. Which approach using the xml.etree.ElementTree module is most appropriate?

Medium
4

When using configparser, how do you retrieve a value as a boolean?

Easy
5

You are using the `json` module to serialize a custom object that contains a `datetime.date` attribute. When you call `json.dumps(obj)`, you get a `TypeError: Object of type date is not JSON serializable`. Which approach correctly allows serialization while preserving the date as an ISO 8601 string?

Hard
6

You are writing a script that reads a large CSV file using csv.reader. The file uses a semicolon as the delimiter and contains quoted fields with embedded newlines. Which instantiation correctly handles this format?

Easy
7

You are writing a Python application that must parse a configuration file where a value spans multiple lines, such as a long list of email addresses separated by newlines. You decide to use the configparser module. Which of the following correctly describes how to include a multi-line value in the configuration file?

Medium
8

You are logging events with custom levels. How do you add a custom level 'TRACE' (value 5) to the logging module?

Hard
9

In the context of the CSV module, what is a 'dialect'?

Easy
10

You are working with a large XML file and need to extract specific elements efficiently without loading the entire document into memory. You decide to use the xml.etree.ElementTree module. Which of the following methods should you use to iterate over all 'book' elements in the document?

Hard
11

When using configparser, what happens if you attempt to read a configuration file that does not exist using the read() method?

Medium
12

You are writing a Python script that must process a large text file line by line. The file is UTF-8 encoded, but some lines contain characters that are not representable in the default system encoding. You want to ensure that the script reads the file correctly on any platform. Which code correctly opens the file?

Medium
13

Which TWO of the following are valid ways to define a configuration option in configparser?

Medium
14

You are writing to a CSV file. If your data contains the delimiter character itself (e.g., a comma in a text field), what does the csv module do by default?

Medium
15

You are using the csv module to read a file that contains fields with embedded newlines and commas. Which TWO of the following statements about the csv.reader are correct? (Choose two.)

Medium
16

When parsing XML with ElementTree, how do you retrieve the text content of an element?

Easy
17

You are building a Python application that uses the shelve module to store persistent data. You want to ensure that the database file is updated correctly and that you can access keys as attributes. Which TWO of the following statements about the shelve module are true? (Choose two.)

Medium
18

A colleague's script parses a CSV export that uses a semicolon as the field separator and contains quoted text fields with embedded semicolons. They call csv.reader(f) without arguments and complain that rows are split incorrectly into too many fields. What is the correct fix?

Medium
19

Which THREE of the following are valid parameters for the csv.writer constructor?

Medium
20

You are writing a Python script that must read a configuration file in TOML format. Which module from the Python Standard Library should you use?

Easy
21

You are working with the sqlite3 module to build a small inventory application. You need to execute a parameterized INSERT statement and then retrieve the auto-generated primary key for the newly inserted row. Which two approaches are valid and safe? (Choose two.)

Medium
22

You are writing a reusable module that must expose only a small public API while keeping several helper functions and constants internal. Users of the module should not import the helpers with 'from mymodule import *', but direct access such as mymodule._helper() may still be needed for tests. Which approach fits best?

Hard
23

You are writing a Python script that needs to create a temporary directory, write several files into it, and ensure that the directory and its contents are automatically deleted when the script exits, even if an exception occurs. Which approach using the tempfile module is most appropriate?

Easy
24

You are using configparser and want to access a value that might not exist, but provide a default value if it is missing. Which method is most appropriate?

Medium
25

When executing a SQL query with parameters in sqlite3, why should you use placeholders (e.g., ?) rather than f-strings?

Medium
26

You are using the datetime module to calculate the difference between two dates. You have two datetime objects, start and end, and you need to find the number of full days between them, ignoring any fractional part. Which expression correctly computes this?

Hard
27

You are using the sqlite3 module to insert a large number of rows into a table. You want to maximize performance by reducing the number of disk writes. Which approach is most effective?

Hard
28

Which THREE of the following are valid methods of the xml.etree.ElementTree.Element class?

Hard
29

You are using the sqlite3 module to manage a database. You need to ensure that database changes are permanently saved even if your script terminates unexpectedly. Which method should you call after an INSERT operation?

Medium
30

Which TWO of the following are valid ways to create a connection in the sqlite3 module?

Easy
31

In the csv module, how do you specify that the CSV file uses a semicolon (;) as a delimiter?

Medium
32

Which method in the xml.dom.minidom module is used to retrieve the value of a specific attribute of an element?

Medium
33

You want to execute multiple SQL statements at once in sqlite3. Which method should you use?

Medium
34

You are writing a Python utility that copies a directory tree to a network share using shutil. You must preserve file metadata and fail loudly if the destination already contains a conflicting file, rather than silently overwriting it. Which TWO shutil features satisfy these requirements? (Choose two.)

Hard
35

You are building a desktop tool with tkinter. A user clicks a button, and while a long file-compression routine runs you want a small window with a progress bar to stay visible and animated; the main application window must remain responsive to the user's clicks throughout. Which approach should you use?

Medium
36

You are building a Python script that needs to create a ZIP archive containing files from a directory. You want to preserve the directory structure inside the archive. Which approach using the zipfile module correctly adds the file '/data/reports/summary.txt' as 'reports/summary.txt' inside the archive?

Hard
37

When using configparser, how do you handle multiline values?

Hard
38

When using sqlite3.Row, what is the primary benefit over using a standard tuple?

Easy
39

You are configuring a logging FileHandler. What does the 'mode' parameter control?

Medium
40

Which TWO of the following are required to successfully write a row to a CSV file?

Medium
41

You are developing a Python script that needs to determine the absolute path of a file located in a directory relative to the script's location. You decide to use the os.path module. Which of the following functions should you use to obtain the absolute path without resolving symbolic links?

Hard
42

You are using configparser.ConfigParser to read a configuration file. You have a file where option names are case-sensitive. How do you ensure the parser respects this casing?

Hard
43

You are configuring logging using a dictConfig. You want to send logs to a RotatingFileHandler. Which key must you define in the 'handlers' section?

Hard
44

You need to configure the logging module to capture logs from multiple modules while ensuring that logs from third-party libraries (e.g., 'urllib3') are only captured at the WARNING level. How do you set this?

Medium
45

You are building a configuration manager that reads an INI file. A section contains the key-value pair `timeout = 30`. You need to retrieve the value as an integer, but if the key is missing, you want to get 60 without raising an exception. Which code snippet achieves this using the `configparser` module?

Medium
46

You are processing a CSV file using csv.DictReader. If your input file lacks a header row, how do you provide the field names?

Medium
47

You are using sqlite3 and need to enforce foreign key constraints. How do you enable them?

Medium
48

Which TWO of the following are true about the sqlite3.Cursor object?

Hard

Frequently asked questions

What does the Library Modules domain cover on the PCPP1 exam?
You must be able to configure csv dialects, read xml.dom.minidom attributes correctly, copy directory trees with shutil while preserving metadata and controlling overwrite behavior, and keep tkinter windows animated during long work. The key skill is choosing the exact argument or method that matches the required behavior.
How many questions are in this domain?
This page lists all 48 Library Modules questions in the PCPP1 question bank. The actual exam draws from this domain proportionally to its weighting in the official exam blueprint.
What is the best way to practise this domain?
Start with a short focused session (10 questions) to identify gaps, then work through explanations. Repeat with a longer session once the weak areas feel solid.
Can I practise only Library Modules questions?
Yes — the session launcher on this page filters questions to this domain only. Choose any session length for inline explanations and scoring.
Python Institute Certified Professional in Python Programming 1 (PCPP1, PCPP-32-101) (PCPP1) Library Modules Practice Questions