Where to Go Next

You can now open a file safely and close it every time, read and write text in whatever shape the job needs, name the encoding so it works on any machine, build and inspect paths with pathlib, list a folder and find files by pattern, parse CSV and JSON properly, and copy, move, delete, compress, and back things up. The last chapter put all of it into one working script.

That covers almost everything you'll meet day to day. A few places to go when you need more.

When a file isn't the right tool

Once your data has relationships in it, or you're reading and updating the same records constantly, a file stops being comfortable. sqlite3, in the standard library, gives you a real database in a single file with no server to run. It's the natural next step up from a CSV that keeps growing.

Deeper on the topics here

  • Encodings. The Unicode HOWTO in the Python docs is the long version of Chapter 4, worth reading once.
  • Binary formats. struct has a full table of format codes, and mmap lets you treat a large file as if it were a bytes object in memory.
  • Archives. zipfile supports password-protected entries, and the lzma and bz2 modules handle the other compression formats you'll occasionally see.

Making it a real command-line tool

The script in Chapter 12 runs one way. To take options like --year 2025 or a different input path, you want argparse from the standard library. That is its own small skill, and it's the subject of another book in this series.

The rest of this track

The full Intermediate track of The Python Crown, in the order to read it:

  • Python File Handling (this book)
  • Decorators and Closures
  • Iterators and Generators
  • Type Hints in Python
  • Testing Python with pytest

Whichever titles are ready are at king-coding.com.