Source: https://mokxi.com/teachers/plans/python-automation
Updated: 2026-11-19

Lesson plan

# Automate it with Python lesson plan

Let Python do a lab's chores: command-line tools with argparse, safe bulk renaming, logging, schedules that keep time, a watched inbox folder, reports written for you, and a lab notebook bot with a live temperature sensor.

4 chapters, 7 lessons, about 5 hours, on the Raspberry Pi 4 Model B. Every lesson runs in the browser, with nothing to install.

Start a class from this course

The unit

## Objectives and materials

### By the end, students can

- Scripts with real options, and changing a folder of files without fear.
- Know what your script did, and run it on time.
- React to files as they arrive, and turn data into reports.
- A lab notebook bot built from everything in the course.

### Materials for the whole unit

- Half breadboard
- LED x 2
- Pressure, humidity and temperature, BME280
- Pushbutton
- Raspberry Pi 4 Model B
- Raspberry Pi Zero 2 W
- Resistor x 2

Every part is already on the simulator’s bench, so there is nothing to buy or hand out. The counts are the most any one lesson uses, if you build it on real breadboards too.

Chapter 1. About 1 h 30 min

## Tools

Scripts with real options, and changing a folder of files without fear.

Lesson | Time | What students do

Scripts and argparse Turn a program into a command-line tool: sys.argv, an argparse parser with a positional, options, types, choices and defaults, a real LED blinked by the arguments, --help for free, clear errors, and arguments typed live in the Serial Monitor. | 50 min

- What a script is given
- A parser
- Arguments that do something
- --help for free
- Clear errors
- A command line in the Serial Monitor

Bulk renaming Rename a folder of microscope photos safely: a regular expression that reads messy names, a plan before any change, conflicts found before they destroy a file, a dry run, the real rename, and an undo log in JSON. | 40 min

- A messy folder
- Plan the new names
- Find the conflicts
- Dry run, then rename
- An undo log

### Materials

- Half breadboard
- LED x 2
- Raspberry Pi 4 Model B
- Resistor x 2

### Check for understanding

Each student finishes "Bulk renaming" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "An undo log".

Chapter 2. About 1 h 20 min

## Logs and time

Know what your script did, and run it on time.

Lesson | Time | What students do

Logging Replace print with logging: five levels, a format with the level and logger name, levels that filter, named loggers per part of a program, a log file that keeps only what matters, and tracebacks with log.exception. | 40 min

- Levels
- Filter by level
- Named loggers
- A log file
- Tracebacks in the log

Scheduling on the clock Run jobs on time: a sleep loop and the drift it builds up, a fixed-rate schedule that does not drift, several jobs at different rates, the next 09:00 worked out with datetime, and a clean stop with Ctrl-C. | 40 min

- The drifting loop
- A fixed-rate schedule
- Several jobs
- At a time of day
- Stop cleanly

### Materials

- Half breadboard
- LED x 2
- Raspberry Pi 4 Model B
- Resistor x 2

### Check for understanding

Each student finishes "Scheduling on the clock" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Stop cleanly".

Chapter 3. About 1 h 20 min

## Pipelines

React to files as they arrive, and turn data into reports.

Lesson | Time | What students do

Watching a folder Process files the moment an instrument drops them: a button that writes sample files, a polling watcher that spots new names, processing and moving each file so it is done once, bad files sent to an errors folder, and a running count. | 40 min

- An instrument that drops files
- Spot new files
- Process and move
- Bad files go aside
- A running count

Reports Turn a class experiment's CSV into a report nobody has to type: load and convert, group into means, write a Markdown table to report.md, add highlights, and fill a message from a string.Template. | 40 min

- The experiment
- Group into means
- A Markdown table
- Highlights
- Fill in a message

### Materials

- Half breadboard
- LED x 2
- Pushbutton
- Raspberry Pi 4 Model B
- Resistor x 2

### Check for understanding

Each student finishes "Reports" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Fill in a message".

Chapter 4. About 40 min

## Boss

A lab notebook bot built from everything in the course.

Lesson | Time | What students do

Boss: a lab notebook bot A bot that keeps the lab's notebook: notes with time stamps in Markdown, measurements from a live temperature sensor on a fixed-rate schedule with argparse options, bad arguments logged instead of crashing, a report, and a logged alarm. | 40 min

- The notebook
- measure, with options
- Bad arguments do not kill the bot
- report
- The alarm

### Materials

- Pressure, humidity and temperature, BME280
- Raspberry Pi Zero 2 W

### Check for understanding

Each student finishes "Boss: a lab notebook bot" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "The alarm".

Your class

## Teach this unit as a class

Start a class from this course and its 7 lessons are assigned in one go, in order. Students join with a six-character code or printed login cards, and each one’s work comes back to you.

The class tools are free for 30 days for one class of up to 20 students, with no card. The lessons themselves are free either way.

Start a class from this course See the demo class

More units

## Other lesson plans

Electronics basics 20 lessons, about 10 h. Embedded on the Arduino Uno 16 lessons, about 12 h. Embedded on the ESP32-C3 13 lessons, about 11 h. Embedded on the Raspberry Pi Pico 7 lessons, about 6 h. Build your own fight stick 5 lessons, about 4 h. Embedded on the STM32F411 6 lessons, about 6 h. C++ on a board 13 lessons, about 10 h. Digital logic and memory 4 lessons, about 4 h. Interactive devices on the Uno 9 lessons, about 8 h. From gates to a computer 23 lessons, about 16 h. Build a claw machine 8 lessons, about 6 h. Every unit All the courses as ready-made units, on the teachers page.
