October 2018
Beginner to intermediate
466 pages
12h 2m
English
Normally, in Python, the singleton pattern can be sufficiently mimicked using module-level variables. It's not as safe as a singleton in that people could reassign those variables at any time, but as with the private variables we discussed in Chapter 2, Objects in Python, this is acceptable in Python. If someone has a valid reason to change those variables, why should we stop them? It also doesn't stop people from instantiating multiple instances of the object, but again, if they have a valid reason to do so, why interfere?
Ideally, we should give them a mechanism to get access to the default singleton value, while also allowing them to create other instances if they need them. While technically not a ...