Brainlag
  1. Python
  2. Errors and files
23/42 lessons

Reading and writing files

30 min5 exercisesPremium

Python file I/O: open files with with, read lines and strip them, write and append text, and read CSV rows with csv.DictReader.

The skill
Read and write text and CSV files, cleaning each line as you go.
You make
A playlist numberer, a high score saver and a CSV mark averager.

Premium lesson

£7.99 a month or £59 a year. Cancel any time.

Builds on 22 Modules and the standard library. Free to try: Python Foundations and the playground.

Step 1 of 9
exercise_1.py

You've reached the good stuff.

5 exercises in this lesson, checked as you type. Premium opens every lesson after Foundations, in all four courses.

Python 3.13