• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 3 out of 29 pages
Exam (elaborations)

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

Document preview thumbnail
Preview 3 out of 29 pages

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

Content preview

D 522 Exam 2 V3 | D 522 Python for IT Automation
| Actual Q&A with Rationale (D522 Exam 2) |
Western Governors University
1. Which module is considered the modern standard for executing external system

commands and capturing their output in Python automation?

A. os


B. subprocess


C. sys


D. shutil


Correct Answer: B


Explanation: The subprocess module is designed to replace older modules like os.system

and os.spawn. It provides a more flexible interface for spawning new processes and

connecting to their input/output/error pipes. For IT automation, subprocess.run() is

preferred as it allows scripts to wait for command completion and easily capture the return

code and output.


2. When using the ‘re’ module to extract a specific pattern from a log file, which method

returns all non-overlapping matches as a list of strings?

A. re.search()


B. re.match()

,C. re.findall()


D. re.split()


Correct Answer: C


Explanation: The re.findall() function scans the entire input string and returns all

occurrences of a pattern in a list. This is particularly useful in automation for tasks like

extracting all IP addresses or timestamps from a large text file. Unlike re.search(), which

only finds the first match, findall ensures all relevant data points are collected.


3. In a try-except block, which keyword is used to execute a block of code only if no

exceptions were raised in the try block?

A. else


B. finally


C. catch


D. then


Correct Answer: A


Explanation: The else clause in a Python exception handling structure runs only when the

code in the try block completes successfully without errors. This is useful for logic that

should only occur if the initial operation, such as opening a file, succeeded. It helps separate

the main logic from the error handling code to improve readability.

, 4. Which method from the ‘csv’ module allows you to read a CSV file where each row is

mapped to a dictionary?

A. csv.reader()


B. csv.DictReader()


C. csv.write_dict()


D. csv.load_json()


Correct Answer: B


Explanation: The csv.DictReader class creates an object that operates like a regular reader

but maps the information in each row to a dict whose keys are given by the optional

fieldnames parameter. If fieldnames is omitted, the values in the first row of the file will be

used as the fieldnames. This is highly efficient for automation tasks where columns need to

be accessed by name rather than index.


5. When using ‘subprocess.run()’, which argument must be set to ‘True’ to capture standard

output and standard error so they can be accessed via the result object?

A. shell


B. capture_output


C. check


D. timeout


Correct Answer: B

Document information

Uploaded on
September 24, 2026
Number of pages
29
Written in
2026/2027
Type
Exam (elaborations)
Contains
Questions & answers
$19.38

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.
Shinnie
3.6
(7)
Sold
27
Followers
0
Items
4868
Last sold
1 week 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