Python 5.3The video for this lesson is on its way.
Everything else is ready: study the parts, the key terms and the quiz below.
Python 5.3Code walkthrough9 parts
Working with Files
Read and write text, CSV and JSON files.
Loading your progress…Next: 5.4 Exceptions
In this lesson9 parts
- 01The reviews in a file
- 02Paths
- 03Writing and reading text
- 04Modes
- 05Encodings
- 06CSV
- 07JSON
- 08The reviews, counted from the file
- 09Recap, your challenge, and next
Key terms
The words this lesson introduces, each in one line. The module’s glossary collects them all.
- CSV
- A table stored as text, one row per line, values separated by commas. A value with a comma in it is written in quotes.
- encoding
- The rule that turns text into bytes, and bytes back into text. This course always uses UTF-8.
- file object
- What
opengives back; you read from it or write to it.withcloses it. - JSON
- A text format for dictionaries, lists, strings and numbers. It has no tuples.
- path
- The folders and the file name that locate a file:
Path("data") / "notes.txt".
Quiz 5 questions
Your first pick on each question is the one that counts, and a right one earns a coin. Getting one wrong here is how the lesson sticks.
Practice
Problems to solve in your own notebook. Each states the problem, not the steps: working out the steps is the exercise. Level A applies the lesson, B combines it with earlier ones, C stretches it.
The self-checking notebook for this lesson is Notebook 2 · Files and Exceptions.
Common mistakes
What you will see when it goes wrong, why it happens, and the fix.
Where it’s used
Where this lesson’s ideas turn up in real work.