◇ OpenCyber Academy
Technical · Chapter 5 · English

Chapter 5 — Checking settings with Python

Open, free learning for anyone who wants to protect people and technology. No account is required to read this text or its worked answers.

Chapter 5 — Checking settings with Python

Lesson map

Lesson 05 published. Map, example, EX017.

flowchart TD
  N0["Learning outcomes"]
  N1["5.1 Why scripts help"]
  N2["5.2 Reading data"]
  N3["5.3 Clear results"]
  N4["5.4 Keeping scripts safe"]
  N0 --> N1 --> N2 --> N3 --> N4
  N4 --> EX["Worked example"]
  EX --> Q["Exercise EX017"]

Logical drawing

flowchart LR
  N0["Learning outcomes"]
  N1["5.1 Why scripts help"]
  N2["5.2 Reading data"]
  N3["5.3 Clear results"]
  N4["5.4 Keeping scripts safe"]
  N0 --> N1 --> N2 --> N3 --> N4 --> Q["EX017"]
[Learning outcomes]
    |
    v
[5.1 Why scripts help]
    |
    v
[5.2 Reading data]
    |
    v
[5.3 Clear results]
    |
    v
[5.4 Keeping scripts safe]
    |
    v
[Worked example] --> [Exercise EX017]

Learning outcomes

You will (1) write a short Python script; (2) read a CSV file of device information; (3) print a clear list of problems.

5.1 Why scripts help

Checking sixty-four devices by hand takes hours and mistakes are easy. Chloe learns to write short Python scripts using only the standard library. Her first script reads a CSV file listing each device with its type, centre and date of last update, and prints how many devices there are of each type. Mr. Appiah explains that even a few lines of code can save time and make checks repeatable, so the same check gives the same answer each week. She runs the script every week.

5.2 Reading data

Chloe uses the csv module to read the file one row at a time. She learns to handle rows with missing values by printing a warning instead of letting the script stop. She tests the script with a file containing a deliberate mistake. Mr. Appiah reminds her that real data always contain errors, so a good script tells you about bad rows rather than quietly skipping them. Her test file has three deliberate mistakes, and the script warns about all three with the row number, so she knows exactly where to look.

5.3 Clear results

Chloe's script prints a heading, the date, the number of devices checked and a list of devices needing attention, grouped by centre. She saves the list to a new CSV file so Mr. Doyle can open it in a spreadsheet. Mr. Appiah asks her to explain each line of the output to a classmate. If the classmate understands it, the output is clear enough for a busy IT lead. Mr. Doyle opens the saved file and says it is exactly what he needs for planning visits to each centre.

5.4 Keeping scripts safe

Chloe keeps her scripts in a folder on the college system, adds comments explaining what each part does and never puts passwords in a script. Output files that list devices are kept in a restricted folder, because a list of weak devices could help an attacker. She learns that tools for checking security must be handled carefully themselves. She also writes a short note at the top of each script explaining what it checks and what file it needs. Mr. Appiah says these notes will help anyone who uses the scripts later, including Chloe herself months from now.

Worked example

Chloe writes a standard-library script that reads device data, warns about bad rows, prints a clear list by centre and keeps scripts and outputs safe.

Synthetic case. Data are synthetic.

Errors and limits

Scripts that skip bad rows quietly can hide problems.

Exercises

Continue studying — lesson 05 (chapter 05 of 18)

← Chapter 04 · Course chapter index · Chapter 06 →

Continue to the next authored lesson.