Last Updated: May 22, 2026
open() takes a mode string like "r" or "w". That string is doing a lot of work. It tells Python whether to read or write, whether to create the file if it doesn't exist, whether to wipe what's there, whether to treat the contents as text or raw bytes, and where the cursor should start. This lesson breaks the mode string apart, walks through every flag (r, w, a, x, b, t, +), shows the useful combinations, and covers three keyword arguments that change behavior just as much: encoding, newline, and buffering.