Offline-ready lesson · progress saves on this device
Typing practiceStudy workspace →
Courses/Intermediate Python/Lesson 2

Lesson 2 of 5

File Handling & Data Processing

Read the overview in
English overview

Read and write files safely, choose CSV for flat tables and JSON for structured data, and use context managers and libraries to avoid data loss.

1 hr 15 minIntermediateDetailed notes6 flashcards + 6 questions
Course outlineIntermediate Python

Why this lesson matters

Read and write files safely, choose CSV for flat tables and JSON for structured data, and use context managers and libraries to avoid data loss.

The goal is not to memorize vocabulary. By the end of the lesson, you should be able to use the ideas in a realistic situation, explain the reason for your choices, and check whether the result actually works for the intended person or task.

Learning objectives

  • Explain File mode in your own words.
  • Apply CSV to a realistic classroom or community example.
  • Connect File mode with JSON when making a decision.
  • Complete the practice task and reflect on one improvement.

Core ideas

1. File mode

The instruction passed to open—such as read, write, or append—that determines what operations are allowed and whether existing content is preserved.

In practice: Look for this idea while you complete the lesson task. Pause before each major step and explain how File mode changes what you choose, create, or check.

2. CSV

A plain-text format for flat rows and columns that is easy to exchange with spreadsheets but stores values as text.

In practice: Look for this idea while you complete the lesson task. Pause before each major step and explain how CSV changes what you choose, create, or check.

3. JSON

A text format that preserves nested objects, arrays, numbers, booleans, and text for structured data exchange.

In practice: Look for this idea while you complete the lesson task. Pause before each major step and explain how JSON changes what you choose, create, or check.

How the ideas connect

Start with File mode to understand the foundation of the lesson. Use CSV to turn that understanding into an action. Then apply JSON to check the quality, safety, or usefulness of the result. The three ideas are strongest when you can explain their relationship rather than treating them as separate definitions.

Guided walkthrough

  1. Name the goal. In one sentence, write what you are trying to understand, create, or improve.
  2. Make a prediction. Before touching a device, use File mode and CSV to predict what a strong result should look like.
  3. Complete the task. Load a small CSV of community resources, calculate a count by category, and save a JSON summary. Handle a missing file without crashing the program.
  4. Check the outcome. Use JSON to inspect the result. Ask what worked, what did not, and what evidence supports your judgment.
  5. Explain and revise. Tell a partner what you changed and why. Make one small improvement, then compare the new result with the first one.

Worked classroom scenario

Imagine two learners sharing one device. The first learner is the driver and performs the steps; the second is the navigator and reads the goal, predicts the next step, and checks the result. Halfway through the task, switch roles. Both learners should be able to explain how File mode, CSV, and JSON appeared in the work.

If no device is available, complete the same reasoning on paper: sketch the screen or result, label each decision, and describe what you would test when a device becomes available.

Common mistakes and fixes

  • Rushing into the tool: Write the goal and prediction first so every click or step has a reason.
  • Copying without understanding: After each major step, explain it in your own words to a partner.
  • Accepting the first result: Compare the outcome with the goal and make at least one deliberate improvement.
  • Letting one person control a shared device: Rotate driver and navigator roles so both learners think and practice.

Independent practice

Load a small CSV of community resources, calculate a count by category, and save a JSON summary. Handle a missing file without crashing the program.

For an extra challenge, adapt the task for a different audience or community need. Write two sentences explaining what changed and which lesson idea guided your decision.

Check your understanding

  1. How would you explain File mode to someone new to the topic?
  2. What is one realistic example of CSV outside this classroom?
  3. When might JSON prevent a weak, unsafe, or confusing result?
  4. How are File mode and CSV connected?
  5. What evidence would convince you that your practice result works?
  6. If you repeated the activity tomorrow, what would you improve first and why?

Key takeaway

Read and write files safely, choose CSV for flat tables and JSON for structured data, and use context managers and libraries to avoid data loss.

You are ready to move on when you can explain the three core ideas, complete the practice without copying, and describe one improvement using evidence from your result.