Skip to content

Archive

Standard Library

147 articles
Python 02 Sep 2026 8 min read

Practical Function Specialization in Python with functools.partial

Functions often expose more parameters than a particular caller needs to choose. A parser may always use the same base, a callback may need access to one application object, or a formatting function may use a fixed prefix throughout one subsystem. Python’s functools.partial() can turn such a general callable into a more focused callable by binding some arguments in advance. The result remains callable, so it can be passed to APIs that expect a function-like object without introducing a wrapper function solely to carry configuration.

Python 02 Sep 2026 9 min read

Practical File Paths in Python with pathlib

Filesystem paths look simple until code has to run from a different working directory, support multiple operating systems, handle symbolic links, or distinguish path manipulation from actual filesystem access. Python’s pathlib module provides path objects that make those distinctions explicit. Instead of repeatedly joining and splitting strings, code can express operations such as “the parent directory,” “this file’s suffix,” or “this path relative to that directory” directly. The most useful habit is not merely replacing os.path calls with methods. It is understanding which pathlib operations are lexical, which consult the filesystem, and when resolving a path changes its meaning.

Python 02 Sep 2026 8 min read

Maintain Sorted Sequences in Python with bisect

A sorted list is useful when a program needs ordered iteration and frequent searches but does not require the repeated minimum extraction of a priority queue. Python’s bisect module provides binary-search operations for this exact representation. The module does not create a special container. It works with an existing sorted sequence and finds the position where a value belongs. That makes it small and predictable, but it also means the caller is responsible for preserving sorted order and understanding that inserting into a Python list still requires moving elements.