MODULE 05 · INTERMEDIATE

Files, Data Formats, and ErrorsPython · Module 5

Read and write portable files, exchange structured data, and make failures explicit without losing information.

5 lessons20 min readingBuild reliable programs
Free, self-paced, and open to everyone. No account needed.
WHAT THIS MODULE COVERS

Files, Data Formats, and Errors

Read and write portable files, exchange structured data, and make failures explicit without losing information.

BEFORE YOU START

Functions, imports, and basic Python syntax.

WHAT YOU’LL BE ABLE TO DO

Read and write portable text files, parse JSON and CSV data safely, and handle expected failures (missing files, malformed data) precisely with try/except blocks.

THE LESSON SEQUENCE

Read in order, or jump to what you need.

Every lesson builds on the one before it. Open any lesson to read the explanation, run the examples, and try the practice challenges.

  1. 05.01
    Paths and Text Files

    Treat file locations, text encodings, and resource lifetimes as deliberate parts of your program.

    4 min
  2. 05.02
    Text file workflows: rewrite, censor, and compare

    Read files line by line, rewrite them without corrupting the original, and verify copy, rename, and search operations.

    4 min
  3. 05.03
    JSON and CSV

    Turn external representations into validated Python values and export data without breaking its structure.

    4 min
  4. 05.04
    Exceptions and Validation

    Give failures useful meaning and recover only when your program knows what recovery should do.

    4 min
  5. 05.05
    Context Managers

    Use with to make resource ownership and cleanup reliable on both success and failure.

    4 min
MODULE SELF-CHECK

Ready to move on?

Test valid input, missing files, empty files, and malformed input; explain exactly which cases should succeed and which should fail with clear error messages.

Open the module self-check