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 27 pages
Exam (elaborations)

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

Document preview thumbnail
Preview 3 out of 27 pages

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

Content preview

D 522 Exam 1 V1 | D 522 Python for IT
Automation | Actual Q&A with Rationale
(D522 Exam 1) | Western Governors
University
1. Which module in Python is most commonly used for interacting with the operating system

to perform tasks like listing directory contents?

A. sys


B. os


C. subprocess


D. shutil


Answer: B


Rationale: The os module provides a portable way of using operating system dependent

functionality. While subprocess is used for external commands, the os module is

specifically designed for file system navigation and environment interaction. This is a

fundamental concept in IT automation for managing local file structures.


2. When using the ‘csv’ module to read a file, which object type does ‘csv.DictReader’ return

for each row in the iteration?

A. Dictionary


B. Tuple

,C. List


D. String


Answer: A


Rationale: The csv.DictReader function maps the information in each row to an

OrderedDict, where keys are the column headers. This allows developers to access data by

column name rather than index, improving code readability. Using dictionaries for data

manipulation is a key skill in Python for IT Automation workflows.


3. What is the primary purpose of the ‘with’ statement when opening a file in Python?

A. To increase the speed of reading the file


B. To encrypt the file contents upon opening


C. To automatically handle file closing even if an exception occurs


D. To allow multiple users to write to the file simultaneously


Answer: C


Rationale: The ‘with’ statement simplifies exception handling by encapsulating common

preparation and cleanup tasks. It ensures that the file is properly closed after the block of

code is finished, preventing resource leaks. This practice is essential for robust automation

scripts that handle many files.


4. In a regular expression, which special character is used to match the start of a string?

A. $

, B. ^


C. .


D. []


Answer: B


Rationale: The caret character (^) anchors the search to the beginning of the string or line.

This is frequently used in log analysis to find lines starting with specific timestamps or

error levels. Mastering regex anchors is vital for precise text processing in IT environments.


5. Which method from the ‘subprocess’ module is recommended for executing a command

and waiting for it to complete in Python 3.5+?

A. subprocess.run()


B. subprocess.popen()


C. subprocess.call()


D. subprocess.check_output()


Answer: A


Rationale: subprocess.run() was introduced in Python 3.5 as the primary way to run

commands. It returns a CompletedProcess instance, which makes it easier to check return

codes and capture output. It is generally preferred over older methods like subprocess.call

for modern automation tasks.

Document information

Uploaded on
July 16, 2026
Number of pages
27
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