May-29-2019, 05:13 PM
(This post was last modified: May-29-2019, 05:13 PM by Gribouillis.)
A python class is not only a class, it is also a callable that returns instances. With this decorator, after
IMHO it is a huge waste of time to spend hours on the singleton pattern in python. Python is for responsible adults, so if you want a singleton, just create a single instance.
@singleton class A: passthe object named
A
in the current namespace is not a class. Instead it is a function that returns A instances. The code supposes that you're not interested in anything else about A. You can still writea = A()and get (the only) instance of the class. But you cannot do
A.some_static_member
and get the corresponding member of class A.IMHO it is a huge waste of time to spend hours on the singleton pattern in python. Python is for responsible adults, so if you want a singleton, just create a single instance.