WGU D522 Python for IT Automation Guide

How WGU D522 Python for IT Automation works, plus original scripts for log parsing, looping over hosts, file cleanup, and network checks with Python.

Stuck on WGU D522 Python for IT Automation? A tutor can walk you through it, one on one. Get help

Last checked: November 9, 2026. Course details come from WGU’s B.S. Cybersecurity and Information Assurance program guide, the WGU Institutional Catalog (October 2026), and WGU’s Accelerated IT transfer guideline. Codes and requirements can change, so confirm on your WGU course page.

WGU D522 Python for IT Automation teaches you to use Python for everyday IT jobs: reading logs, repeating a task across many machines, and using modules for networking work. It builds on beginner Python. The fastest way through is to automate small, real chores until writing a script feels normal.

WGU doesn’t publish D522’s assessment type on its public pages. Your course page shows whether it ends in an objective assessment (OA) or a performance assessment (PA). Our OA vs PA guide explains how each one works.

WGU D522 at a glance

Course codeD522
Course namePython for IT Automation
Degree programs7, per the October 2026 catalog
Where it sitsIn the B.S. Cybersecurity guide’s programming group, it follows Foundations of Programming (Python) and Version Control
TransferListed as not transferable in WGU’s Accelerated IT guideline, so plan to take it at WGU
Competency units and assessmentNot confirmed on the public pages we checked. See your course page

What is D522 really about?

It’s about using code to do IT work you’d otherwise do by hand. Instead of opening 40 log files, you write a script that opens them for you and reports what matters.

WGU’s program guide describes three areas. In plain English:

  1. Python syntax and data structures for IT tasks. Strings, lists, and dictionaries used to hold things like hostnames, IP addresses, and log lines.
  2. Control structures that automate work. Loops and conditions that repeat a job and make decisions without you.
  3. Modules and libraries for networking tasks. Using Python’s built-in tools, and installed packages, to work with addresses, connections, and files.

Each section below takes one area with an original example. None of these are WGU assessment items.

Do you need E010 or D335 first?

You need beginner Python, whichever course gave it to you. WGU’s B.S. Cybersecurity guide places D522 after Foundations of Programming (Python) and Version Control. If your plan lists E010 Foundations of Programming first, finish it before D522.

D522 vs E010 is a common question. E010 teaches the language itself. D522 assumes you know it and asks you to point it at IT problems. If functions or dictionaries still feel shaky, review them before you start.

How do you use strings and dictionaries for IT data?

Most IT data arrives as text. Your first job is to split that text into pieces you can count and compare.

Worked example: summarizing a log

Here’s a made-up log, one event per line:

log_lines = [
    "2026-11-02 08:14 WARN disk /var at 86%",
    "2026-11-02 08:20 INFO backup finished",
    "2026-11-02 09:03 ERROR service nginx stopped",
    "2026-11-02 09:05 WARN disk /var at 91%",
]

levels = {}
for line in log_lines:
    level = line.split()[2]
    levels[level] = levels.get(level, 0) + 1

print(levels)   # {'WARN': 2, 'INFO': 1, 'ERROR': 1}

line.split() breaks a line on spaces, so position 2 is the level. The dictionary keeps a running tally for each one.

Clean the text before you compare it

Text from files often has stray spaces or a newline at the end. "web01\n" == "web01" is False. Use .strip() to trim it, and .lower() when case shouldn’t matter.

How do loops and conditions automate a task?

A loop repeats the same steps for each item. A condition decides what to do with each one. Together they replace a checklist you’d do by hand.

Worked example: flag low disk space

disks = {"web01": 72, "web02": 94, "db01": 88, "mail01": 41}

for host, used in disks.items():
    if used >= 90:
        print(f"{host}: CRITICAL ({used}%)")
    elif used >= 80:
        print(f"{host}: warning ({used}%)")

This prints web02: CRITICAL (94%) and db01: warning (88%). The healthy hosts print nothing, which is what you want in a report.

Worked example: retry until it works

Some jobs fail once and succeed on the next try. A while loop with a limit keeps you from looping forever:

attempt = 1
max_attempts = 3
done = False

while attempt <= max_attempts and not done:
    print(f"Attempt {attempt}")
    done = attempt == 2       # pretend it works on try 2
    attempt += 1

Always ask, “What makes this loop stop?” If you can’t answer, it might never stop.

Handle errors so one bad item doesn’t stop the run

readings = ["12", "7", "n/a", "30"]
total = 0
for r in readings:
    try:
        total += int(r)
    except ValueError:
        print(f"Skipping bad value: {r}")
print(total)   # 49

Without try and except, the script would crash on "n/a" and never reach "30".

Which Python modules help with networking and files?

You don’t have to build everything yourself. Python ships with modules that already do common IT work. Import one at the top of your file with import.

ModuleWhat it helps with
ipaddressChecking whether an address is valid, and whether it’s inside a network
socketOpening a basic network connection, such as testing if a port responds
subprocessRunning a system command, like ping, from inside Python
os and pathlibListing, moving, and checking files and folders
csv and jsonReading and writing data files that other tools use
datetimeTimestamps, and working out how old a file is

Packages from outside the standard library are installed with pip. Your course materials say which ones it uses.

Worked example: which addresses belong to a subnet?

import ipaddress

office = ipaddress.ip_network("10.20.0.0/24")
devices = ["10.20.0.15", "10.20.1.9", "10.20.0.200"]

for d in devices:
    if ipaddress.ip_address(d) in office:
        print(d, "is in the office subnet")

This prints the first and third addresses. 10.20.1.9 is in a different /24 network.

Worked example: is a port open on your own machine?

import socket

def port_is_open(host, port, timeout=2):
    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
        s.settimeout(timeout)
        return s.connect_ex((host, port)) == 0

print(port_is_open("127.0.0.1", 8080))

connect_ex returns 0 when the connection works. Practice only on your own computer or a lab you’re allowed to test.

Worked example: find old files

from pathlib import Path
from datetime import datetime, timedelta

cutoff = datetime.now() - timedelta(days=30)
for f in Path("reports").glob("*.txt"):
    modified = datetime.fromtimestamp(f.stat().st_mtime)
    if modified < cutoff:
        print("Older than 30 days:", f.name)

The script only prints. Before you add a line that deletes, run it and check the list. That habit saves real servers.

A suggested D522 study plan

This is our suggestion, not a WGU timeline. Move to the next step when you can do the current one without notes.

  1. Meet your instructor. Ask how the course is assessed and which tools and packages it expects.
  2. Refresh the basics. Rewrite the log summary above from memory, then add a count by date.
  3. Automate with loops. Take a list of 10 made-up hosts and print a status report with three levels.
  4. Add error handling. Feed your scripts bad input on purpose and make them keep going.
  5. Use modules. Write one small script each with ipaddress, pathlib, and csv.
  6. Combine them. Read hosts from a CSV, check each one, and write the results to a new file.
  7. Review. Work through your course’s practice material and revisit any weak step.

Common D522 mistakes

  • Forgetting .strip() when reading lines from a file, so comparisons fail for no clear reason.
  • Naming your file after a module, like socket.py. Python then imports your file instead of the real module.
  • Loops with no exit. A while True with no break freezes the script.
  • Catching every error with a bare except:. It hides the real problem. Catch the specific error you expect.
  • Running a delete or change before a dry run. Print what would happen first.
  • Installing a package for one Python version and running the script with another.

Practice problems (original)

  1. What does "ERROR disk full".split()[0] return?
  2. Write a condition that is true when a CPU value cpu is between 70 and 89, inclusive.
  3. Is ipaddress.ip_address("192.168.5.20") in ipaddress.ip_network("192.168.5.0/24") true or false?
  4. Your script crashes on int("--"). Which error should you catch?
  5. Why might import csv fail in a folder that holds a file named csv.py?

Solutions

  1. 'ERROR', the first word.
  2. 70 <= cpu <= 89. Python lets you chain comparisons like this.
  3. True. The /24 network covers 192.168.5.0 to 192.168.5.255.
  4. ValueError, because "--" can’t be turned into a whole number.
  5. Python finds your csv.py first and imports it instead of the standard module. Rename your file.

Failed D522? If you did not pass, start here

A result that didn’t go your way isn’t the end. It shows you where to focus. If you took an OA, read your coaching report and rebuild the weakest areas with fresh scripts. If your work came back for revision, our guide to fixing a returned performance assessment shows how to work through evaluator comments. Check the WGU retake policy, try the 7-day WGU retake plan, and talk with your instructor about next steps. The WGU retake hub has more.

Need help with D522?

Start with your WGU course instructor. They know how your version of D522 is assessed and can point you to the right course material.

If you’d like extra practice, PassPathways offers one-on-one WGU tutoring that explains concepts, walks through original practice scripts, and helps you plan your study time. You do all of your own graded work.

WGU D522 FAQ

Is D522 hard? It depends on how comfortable you are with beginner Python. We haven’t found enough public evidence to say how most students find it. If loops, functions, and dictionaries already feel natural, D522 is mostly about applying them to IT tasks.

Can I transfer D522 in? Probably not. WGU’s Accelerated IT transfer guideline lists Python for IT Automation as a course that can’t be transferred. See our B.S. IT transfer map and confirm with your Enrollment Counselor.

What’s the difference between D522 and E010? E010 teaches Python basics. D522 uses those basics for IT jobs such as log parsing, repeated checks, and networking modules. WGU’s B.S. Cybersecurity guide places D522 later in the same programming group.

Does D522 have a practice quiz here? Not yet. WGU doesn’t publish whether D522 ends in an OA or a PA, so we haven’t added one. The practice problems above are a good start.

PassPathways is an independent resource and is not affiliated with WGU. This guide contains original explanations and practice problems, not actual exam questions.

Back to the WGU study guides.

Stuck on this course? Get one-on-one tutoring.

Tell us what you want, and we'll reply with how a tutor can help. We teach and coach. When you're ready, agree to our terms below.

Get started

Learn about WGU tutoring

Want help with WGU D522 Python for IT Automation?

Reading a guide is a great start, but some topics click faster when someone explains them to you. Our tutors work one on one with WGU students.

  1. Tell us where you're stuck. Share your course and what feels hard.
  2. We reply on WhatsApp or email. No forms to wait on if you'd rather chat.
  3. A tutor explains it and builds a plan with you, so you understand the material and pass on your own.
  • Original guides, fact-checked against official WGU sources
  • Honest, ethical tutoring: we teach, you do your own work
  • Free practice quizzes to check your progress
Need help with this course? WhatsApp Message