• 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 4 out of 31 pages
Exam (elaborations)

Wgu D522 Python For It Automation Pa Tasks 1 & 2 Troubleshooting Guide Questions And Correct Answers Plus Rationales| Instant Download

Document preview thumbnail
Preview 4 out of 31 pages

This guide walks through common Python automation problems and their fixes, covering atomic file writes, resilient API parsing, regex validation, subprocess timeouts, config merging, secret handling, log file offsets, rate-limit retries, duplicate logging, malformed JSON, and module import paths. Each question includes the correct answer and a clear rationale, helping you understand why one solution works and others fail. Use it to prepare for the WGU D522 performance assessment tasks.

Content preview

, Question 1
A script that reads a CSV with a header row and writes an updated CSV fails
intermittently under concurrent runs, producing truncated output. Which
change best ensures atomic, consistent writes without sacrificing
cross-platform behavior?
A. Open the destination with mode 'w' and call file.flush() after every row
write.
B. Write to a temp file in the same directory, flush and os.fsync it, then
use os.replace() to atomically swap it into place.
C. Wrap the entire write in a threading.Lock and continue writing directly
to the destination file.
D. Open the destination with mode 'a' and rely on the OS to serialize
concurrent appends.
Correct Answer: B - Write to a temp file in the same directory,
flush and os.fsync it, then use os.replace() to atomically swap it
into place.


RATIONALE
Atomic replacement via os.replace() on a same-directory temp file
prevents readers from observing partial writes and is atomic on POSIX
and Windows. flush() alone does not prevent truncation visibility, a
threading.Lock does not protect across processes, and append mode
still allows interleaved partial records.

Question 2
An automation script raises `KeyError: 'hostname'` only when run against a
particular API response. Which modification most directly produces a resilient
parse while preserving diagnostic information?
A. Wrap the parse in `try/except Exception: pass` to avoid crashing.
B. Replace dict access with `response.get('hostname')` and log a
structured warning when the key is absent.


Page 2

, C. Convert the response to a string and search for the substring

'hostname'.

D. Set a module-level default `hostname = None` and reference it
globally.
Correct Answer: B - Replace dict access with
`response.get('hostname')` and log a structured warning when the
key is absent.


RATIONALE
Using .get() with an explicit warning preserves execution and records
the missing-key condition for troubleshooting. Blanket except
suppresses evidence, substring search is brittle, and a global default
obscures the actual data gap.

Question 3
A regex intended to validate IPv4 addresses uses `^\d{1,3}(\.\d{1,3}){3}$`.
Which input incorrectly passes this pattern, demonstrating the flaw?
A. 192.168.1.1
B. 999.999.999.999
C. 10.0.0.1
D. 172.16.254.1
Correct Answer: B - 999.999.999.999


RATIONALE
The pattern only constrains each octet to 1-3 digits, so
999.999.999.999 matches despite being invalid. Proper validation
must bound each octet to 0-255, which the other listed addresses
satisfy as valid inputs.




Page 3

, Question 4
A subprocess call to a long-running CLI hangs indefinitely in CI but works
locally. Which adjustment most robustly addresses the root cause while
retaining captured output?
A. Use subprocess.run(..., shell=True) to inherit the parent shell
environment.
B. Use subprocess.run(..., timeout=N, capture_output=True) and handle
subprocess.TimeoutExpired.
C. Replace subprocess with os.system() to avoid pipe buffering.
D. Set stdin=subprocess.PIPE without providing input to force EOF.
Correct Answer: B - Use subprocess.run(..., timeout=N,
capture_output=True) and handle subprocess.TimeoutExpired.


RATIONALE
An explicit timeout with captured output prevents indefinite hangs and
surfaces the failure for troubleshooting. shell=True introduces
injection risk without solving hangs, os.system provides no output
capture, and an empty stdin pipe can itself cause blocking.

Question 5
A configuration loader must merge environment-specific overrides onto
defaults without mutating the defaults across repeated calls. Which
implementation correctly avoids shared-state bugs?
A. defaults.update(overrides); return defaults
B. return {**defaults, **overrides}
C. merged = defaults; merged.update(overrides); return merged
D. return dict.fromkeys(defaults, overrides)
Correct Answer: B - return {**defaults, **overrides}




Page 4

Document information

Uploaded on
October 1, 2026
Number of pages
31
Written in
2026/2027
Type
Exam (elaborations)
Contains
Questions & answers
$30.00

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.
CaseHero
3.8
(4)
Sold
20
Followers
0
Items
6237
Last sold
6 days 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