file IO

Read and write files from code: text and binary, reading lines, copying, temp files, and streams, with tested examples and real output.

Python: Context Managers, with Statement & Custom Managers

A Python context manager is the machinery behind the with statement. This post opens it up so you can see exactly how with works under the hood, what the __enter__ and __exit__ methods do, how to build your own context manager with a class or the @contextmanager decorator, and the patterns that stop resource leaks in real apps. “The cleanup code you never run is the bug you never see coming.” Every developer who has leaked a file handle Last ... Read More

Python: Standard Library, 20 Must-Know Modules

The Python standard library ships with 200+ modules, and most developers only ever touch about 10 of them. Here are the 20 modules that save you from reinventing wheels, writing buggy workarounds, and reaching for pip when the answer is already sitting on your hard drive. “Python comes with batteries included.” Guido van Rossum, Python docs Last Updated: July 2026 | Tested on: Python 3.14.6 | Difficulty: Intermediate | Reading Time: 20 minutes The Python standard library is the set ... Read More

Python: Working with CSV and JSON Files

Sooner or later every script produces data worth keeping: a class list, an API response, a config file. Python CSV JSON support is built in for exactly that moment, with csv for spreadsheet-style rows and json for nested data. No pip install, just an import. This post covers reading and writing both formats, then converting between them. “Data is a precious thing and will last longer than the systems themselves.” Tim Berners-Lee Last Updated: July 2026 | Tested on: Python ... Read More