Recipes: File Handling¶
Short, task-focused how-tos for specific things you'll want to do with files. Each recipe assumes you already know the basics — if a term surprises you, the Learn section is one click away.
Unlike the tutorials, the recipes don't have a recommended order. Pick whichever is useful right now.
Recipes in this guide¶
- Process large files — reading files that don't fit in memory, line-by-line processing, and why generators help.
- Work with binary files — opening files in binary mode, handling bytes, and packing/unpacking simple formats.
- Manage temporary files —
tempfilefor scratch files that clean up after themselves. - Avoid common file handling mistakes — forgotten closes, encoding surprises, and other traps.