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 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. When using the subprocess module, which function is recommended for most applications

to execute a child process and wait for it to complete?

A. subprocess.run()


B. subprocess.call()


C. subprocess.popen()


D. subprocess.check_output()


Answer: A


Rationale: The subprocess.run() function was introduced in Python 3.5 and is the current

standard for executing commands. It simplifies the process by waiting for the command to

finish and returning a CompletedProcess instance. This approach is preferred over older

functions like call() because it provides a more robust interface for handling stdout and

stderr.


2. Which regular expression pattern would best identify a standard IPv4 address such as

192.168.1.1?

A. r’...’

,B. r’[a-z]{1,3}.[a-z]{1,3}’


C. r’+.+’


D. r’+’


Answer: A


Rationale: The pattern matches between one and three digits, which corresponds to the

octets in an IPv4 address. The backslash before the dot ensures the literal period is

matched rather than any character. This pattern is fundamental for network automation

scripts that parse log files or configuration outputs.


3. What is the primary benefit of using a context manager (with statement) when opening

files in Python?

A. It automatically closes the file after the block is finished.


B. It encrypts the data written to the file.


C. It increases the speed of file write operations.


D. It allows multiple processes to write to the same file simultaneously.


Answer: A


Rationale: A context manager ensures that file descriptors are released back to the

operating system even if an error occurs within the block. This prevents resource leaks

which can lead to system instability in large automation pipelines. It is a standard Pythonic

best practice that improves code readability and reliability.

, 4. Which method in the ‘os’ module should be used to create a directory if you also need to

create any missing parent directories?

A. os.mkdir()


B. os.path.create()


C. os.system(‘mkdir’)


D. os.makedirs()


Answer: D


Rationale: The os.makedirs() function is recursive, meaning it will create all intermediate-

level directories needed to contain the leaf directory. In contrast, os.mkdir() will raise a

FileNotFoundError if the parent path does not exist. This makes makedirs() highly effective

for setting up log structures or repository paths in automation scripts.


5. In the ‘unittest’ framework, which method is used to verify that two values are identical

during a test case?

A. self.assertTrue()


B. self.assertIdentical()


C. self.checkEqual()


D. self.assertEqual()


Answer: D

Document information

Uploaded on
July 16, 2026
Number of pages
29
Written in
2025/2026
Type
Exam (elaborations)
Contains
Questions & answers
$16.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