File modes in Python PREMIUM

Trey Hunner smiling in a t-shirt against a yellow wall
Trey Hunner
5 minute read Works on Python 3.7—3.10
Python Morsels
Watch as video
03:34

Let's talk about file modes in Python.

Read mode (the default)

The default mode when you open a file is r or rt for read mode:

```pycon

with open("my_file.txt") as f: ...

Write more Pythonic code

Need to fill-in gaps in your Python skills? I send regular emails designed to do just that.