Stumbled upon an interesting trick with Python thanks to a talk on design patterns. The Borg design pattern is new to me, as a replacement for the simpleton. What caught my attention is the way it handles shared state instead of a shared singleton object.
A while back, working with Twitter's streaming API, it came in handy to work with incoming JSON data.
Python objects (modules, instances) hold symbol data and state in a special dict. The hack with the Borg pattern is to reuse this with a shared state dict. Nifty indeed.
I've in the past had flows where I use the setattr on a dict.items() but the simplicity of this one, 🤯
Gist that I used to create nested objects.
Borg design pattern / Repo.
The linked repo contains a handful of Python design patterns; a treasure trove of a reference.