.py

Free web edition

Python File Handling

Reading, writing, and organizing files

A short, example-driven guide to working with files in Python: opening them safely, handling text and encodings, using pathlib for paths, and reading and writing CSV and JSON. Nothing here needs a package you have to install, and every example was run when the book was built. By the end you can get data in and out of a file without looking it up.

Contents

  1. Preface
  2. Introduction
  3. 1. Opening and Closing Files
  4. 2. Reading Text
  5. 3. Writing Text
  6. 4. Text and Encodings
  7. 5. Paths with pathlib
  8. 6. Finding Files
  9. 7. CSV Files
  10. 8. JSON Files
  11. 9. Moving, Copying, and Deleting
  12. 10. Binary and Temporary Files
  13. 11. Compressed Files
  14. 12. Putting It Together
  15. Where to Go Next
  16. About the Author

Why the PDF?

The web edition is the whole book, free. The paid PDF is the same words in a form you can keep: offline, a clickable table of contents and outline, easy to read on a tablet or e-reader, and it pays for the next one.

Get Python File Handling — $12