I always forget it. As a note. (Quoted from expert Python)
my_singleton_class.py
class MySingletonClass(object):
def __new__(clsObj, *args, **kwargs):
if not hasattr(clsObj, "__instance__"):
clsObj.__instance__ = super(MySingletonClass,
clsObj).__new__(clsObj,
*args,
**kwargs)
return clsObj.__instance__
It's a mysterious spell.
Recommended Posts