Python Programming Unit 5

Files, APIs, and Automation

Read real data, automate repeated work, and build practical scripts.

This unit shows students how Python connects to files, folders, APIs, and automation workflows. Students practice text files, CSV files, JSON data, directory paths, reading and writing files, requests, APIs, introductory web data extraction with Beautiful Soup, automation scripts, report generation, data cleanup, environment setup, pip, virtual environments, Jupyter notebooks, and Google Colab.

Who This Unit Is For

Best for students who can use functions and collections and want to build useful scripts, collect public-style data, clean files, or generate reports.

Learning Goals

  • Read and write text, CSV, and JSON data safely.
  • Understand paths, folders, and where files are stored.
  • Use requests to read public API responses and inspect JSON.
  • Write small automation scripts that clean data or generate reports.
  • Use pip, virtual environments, notebooks, or Colab in an organized way.

Key Concepts

What students practice in this unit

Automation is where Python becomes useful outside of practice problems. Students can clean a spreadsheet, collect public data, organize files, or create a weekly summary without doing the same manual work over and over.

File formats

Students learn when plain text, CSV, and JSON are useful and how each one represents information.

Paths and folders

Students practice relative paths, project folders, and avoiding hard-coded machine-specific paths.

API responses

Students inspect status codes, JSON keys, lists, and nested response structures using safe public or placeholder examples.

Automation workflows

Students connect input files, processing steps, and output reports into one repeatable script.

Practice

Exercises and mini-project ideas

These are public practice prompts students can use to strengthen the unit without exposing the full internal lesson sequence.

Practice Exercises

  • Clean a CSV file by trimming spaces and standardizing capitalization.
  • Write a file organizer that groups filenames by extension.
  • Collect sample JSON from a placeholder API and print selected fields.
  • Parse a JSON response into a short summary table.
  • Generate a weekly report from fictional study-hour or club-attendance data.
  • Use a notebook to document each step of a small automation workflow.

Mini-Project Ideas

  • CSV cleanup script for survey responses.
  • Public API data collector with saved JSON output.
  • Weekly report generator that reads data, computes totals, and writes a summary file.

Common Student Mistakes

  • Assuming a file exists without checking the path.
  • Forgetting to close a file or use a with statement.
  • Treating JSON like a string instead of nested dictionaries and lists.
  • Hard-coding one local folder path that will not work on another computer.
  • Calling an API repeatedly without understanding limits or errors.

Challenge Extension

Students add basic error handling for missing files, invalid rows, or an API response that does not contain the expected key.

How This Prepares the Next Step

Students are ready to load datasets into NumPy and pandas, clean larger tables, and start exploratory data analysis.

Related Code Scholars Paths

Ready to practice?

Build Python skills with a guided plan.

Students can use this page for review, then work with Code Scholars on targeted exercises, debugging support, projects, and next-step planning.