Lesson 082

Files & I/O

Persistent storage · open → use → close

1:00

How programs persist data beyond runtime — covering the open/read-write/close lifecycle, file descriptors, text vs binary mode, buffering, the write-is-not-instant trap, and random access with seek and tell.

By the end, you can

  • Explain why files exist and what makes disk storage different from memory.
  • Describe the three-step I/O lifecycle and the consequence of skipping close().
  • Define a file descriptor and identify what descriptors 0, 1, and 2 represent.
  • Distinguish text mode from binary mode and predict what goes wrong when the wrong mode is chosen.
  • Explain why I/O libraries use buffering and quantify the syscall reduction.
  • Trace the path a write() call takes from user-space buffer to durable disk, naming each layer.
  • Use seek() and tell() to navigate a file, and recognize a zero-length read as the EOF signal.
  • Explain why Python's `with open(...)` idiom is safer than manually calling open() and close().
Up next in Math, Memory & Files
Questions or feedback?