Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Document preview thumbnail
Preview 3 out of 29 pages
Exam (elaborations)

D 522 Exam 3 V1 | D 522 Python for IT Automation | Actual Q&A with Rationale (D522 Exam 3) | Western Governors University

Document preview thumbnail
Preview 3 out of 29 pages

D 522 Exam 3 V1 | D 522 Python for IT Automation | Actual Q&A with Rationale (D522 Exam 3) | Western Governors University

Content preview

D 522 Exam 3 V1 | D 522 Python for IT
Automation | Actual Q&A with Rationale
(D522 Exam 3) | Western Governors
University
1. When using the re module in Python, which function should be utilized to find all

occurrences of a pattern within a string and return them as a list?

A. re.search()


B. re.findall()


C. re.match()


D. re.split()


Answer: B


Rationale: The re.findall() function scans the entire string and returns all non-

overlapping matches of a pattern as a list of strings. This is particularly useful for extracting

data like IP addresses or dates from log files where multiple instances may occur. In

contrast, re.search() only returns the first match found, and re.match() checks only

the beginning of the string.


2. Which method from the os module is the most appropriate for checking if a specific file

exists at a given path before attempting to open it?

A. os.access()

,B. os.path.isfile()


C. os.path.exists()


D. os.mkdir()


Answer: B


Rationale: The os.path.isfile() function specifically checks if the target path points to

a regular file, ensuring that the script does not try to process a directory as a file. While

os.path.exists() confirms the path is valid, it does not distinguish between files and

directories. Using this check helps prevent FileNotFoundError exceptions during

automation tasks.


3. In the context of the csv module, what is the primary advantage of using

csv.DictReader over the standard csv.reader?

A. It processes data faster in large datasets.


B. It automatically encrypts the data during the read process.


C. It maps the information in each row to a dictionary using fieldnames.


D. It handles binary files more efficiently than text files.


Answer: C


Rationale: csv.DictReader creates an object that maps the information in each row to a

dictionary whose keys are given by the optional fieldnames parameter or inferred from the

first row. This makes the code much more readable and maintainable because values can

, be accessed via column names rather than integer indices. It reduces errors when the CSV

structure changes, such as when columns are rearranged.


4. A system administrator needs to run an external command from a Python script and

capture its output for logging. Which module is best suited for this task?

A. sys


B. subprocess


C. logging


D. platform


Answer: B


Rationale: The subprocess module allows Python to spawn new processes, connect to

their input/output/error pipes, and obtain their return codes. It is the recommended

standard for executing shell commands and replacing older functions like os.system. This

is critical for IT automation when interacting with legacy scripts or system utilities.


5. Which regular expression character is used to match the start of a string?

A. $


B. ^


C. *


D. +


Answer: B

Document information

Uploaded on
July 16, 2026
Number of pages
29
Written in
2025/2026
Type
Exam (elaborations)
Contains
Questions & answers
$17.99

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
ScholarsAscend
3.7
(77)
Sold
453
Followers
39
Items
29361
Last sold
11 hours ago




Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions