Skip to main content
Loading page…
Python Mastery
Chapter 10
Lesson 1 of 4
Reading & Writing Files
Contents
Notes
Tutor
Concept
Opening Files: The Basics
Loading activity…
Previous
1 / 9
Continue
Contents
Notes
Discussion
Tutor
29 min
9 activities
0 of 9 done
In this lesson
1
Opening Files: The Basics
2
Reading Files: Four Techniques
3
Writing & Appending to Files
4
Pitfall: Always Specify encoding="utf-8"
5
Bridge: Setup Imports in File Exercises
6
Writing a Simple Log File
7
Which read method is best for a 2 GB log file?
8
Practice: Word Frequency Counter
9
Pro Tip: Use pathlib Instead of String Paths
Objectives
Learner can open files safely using the with statement and context managers
Learner can read file contents with read(), readline(), readlines(), and line iteration
Learner can write and append text to files using write() and writelines()
Learner can specify encoding and understand newline handling on all platforms
Chapter 10 · Files, JSON & CSV
Reading & Writing Files
Paths Done Right with pathlib
JSON: Talking to the World
CSV & Tabular Data
Previous: EAFP, Validation & Robust Code
Next: Paths Done Right with pathlib