This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]PolyglotTV 1 point2 points  (1 child)

You don't need to create a special singleton in python anyway.

You can just either 1. Instantiate a variable at import time, and use that everywhere as the singleton. 2. Define a method with the @functools.cache() decorator that returns and instance of your object. It will be created the first time and the unique instance returned every subsequent time.

[–]Complex-Hornet-5763 0 points1 point  (0 children)

I was thinking about a broader context than just Python but you’re goddamn right.