← Reference notes

Reading and writing files in Python

Summary

Use with open(path, mode) as f: and then f.read(), iterate lines with for line in f, or f.write(s). Mode 'r' reads (default), 'w' overwrites, 'a' appends; add 'b' for binary.

Facts

Pointers

Source: https://docs.python.org/3/tutorial/inputoutput.html · License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Source: Python Software Foundation, \"Tutorial 7.2: Reading and writing files (Python 3.15 docs)\" (PSF documentation license; restated, not copied).

For language models and agents: start at /llms.txt. This page in Markdown: /library/reference/python-docs/python-read-write-files.md.