How to Make an Immutable Dict in Python

Python’s built-in collection types come in mutable and immutable flavours, but one is conspicuously missing:
Adam Johnson
Home | Blog | Books | Projects | Colophon | Contact
(All tags.)
Python’s built-in collection types come in mutable and immutable flavours, but one is conspicuously missing:
This post is not about importing typing.Optional
, but instead imports that are themselves optional. Libraries often have optional dependencies, and the code should work whether or not the import is there. A common pattern to solve this to catch ImportError
and replace the module with None
:
If you use Gunicorn, it’s likely you have a configuration file. This is a Python module that contains settings as module-level variables. Here’s an example with some essential settings:
Developer Experience (DX) is a catch-all term for anything that can improve your development workflow. Such improvements can help you write better code, faster, with fewer bugs.
The descriptor protocol allow us to completely customize attribute access. Python’s documentation describes the protocol with types involved described with words. Let’s look at how we can write those as type hints.
Earlier this week I shared my Python script template. Here’s an extended version with sub-command support, and an example script.
When dealing with evolvng API’s, it may be useful to rename an attribute in a class, but keep the old name around for backwards compatibility. This would mean making one attribute an alias for another. In this post we’ll look at two ways to achieve this.
I remain convinced that Python’s functools.partial()
is underappreciated. Following my previous post, here are three more ways to use partial()
with Django.
It’s fundamentally useful to exit your program when it’s done. Here are five(!) ways to do so in Python.
Python is great for writing scripts for the command line. In this post we’ll look at my script template, an example script, and some alternative versions (without type hints, and in async flavour).