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 2 V1 | 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 V1 | D 522 Python for IT Automation | Actual Q&A with Rationale (D522 Exam 2) | Western Governors University

Content preview

D 522 Exam 2 V1 | D 522 Python for IT
Automation | Actual Q&A with Rationale
(D522 Exam 2) | Western Governors
University
1. When using the os.path.join() function in a Python script, what is the primary

advantage for IT automation?

A. It ensures that the correct directory separator is used for the host operating system.


B. It increases the execution speed of directory traversal algorithms.


C. It automatically creates the directories if they do not already exist on the disk.


D. It provides encryption for the file paths to prevent unauthorized access.


Answer: A


Rationale: The os.path.join() function is essential for creating cross-platform scripts

because it automatically uses either a forward slash or backslash depending on the

operating system. Hardcoding slashes leads to errors when scripts are moved between

Windows and Linux environments. This modular approach is a best practice in automation

to ensure reliability across diverse server fleets.


2. In the context of the re module, what is the difference between re.search() and

re.match()?

A. re.search() returns a list, while re.match() returns a single string.

,B. re.match() checks for a match only at the beginning of the string, while re.search()

checks anywhere.


C. re.search() is case-sensitive by default, whereas re.match() is not.


D. re.match() is used for replacement, while re.search() is used only for finding

patterns.


Answer: B


Rationale: The re.match() function attempts to apply the pattern starting exactly from

the first character of the target string. Conversely, re.search() will scan the entire string

until it finds a match for the specified pattern. Understanding this distinction is critical for

IT professionals when parsing log files where patterns might not appear at the start of a

line.


3. Which method from the csv module is most efficient for reading a CSV file into a

dictionary format where the keys are the column headers?

A. csv.reader()


B. csv.writer()


C. csv.load_dict()


D. csv.DictReader()


Answer: D

, Rationale: csv.DictReader 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

data manipulation significantly easier as columns can be accessed by name rather than

index. Utilizing dictionaries for data processing reduces errors caused by column shifts in

automation tasks.


4. What does the capture_output=True argument do when used with

subprocess.run()?

A. It displays the output of the command directly to the system console.


B. It prevents the command from executing if the output exceeds a certain size.


C. It captures both standard output and standard error so they can be accessed in the

script.


D. It redirects the output to a hidden system log file automatically.


Answer: C


Rationale: Setting capture_output=True allows the script to store the stdout and stderr

of the executed command within the returned CompletedProcess object. This is vital for IT

automation because it allows the script to programmatically inspect the results or errors of

a shell command. Without this, the output is typically sent to the console and lost to the

script’s logic.

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
12 hours ago




Why students choose Stuvia

Created by fellow students, verified by reviews

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

Didn't get what you expected? Choose another document

No problem! You can straightaway pick a different document that better suits what you're after.

Pay as you like, start learning straight 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 smashed 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