das Singleton Rezept aus dem Kochbuch funktioniert nicht.
Was ist da falsch ?
Code: Alles auswählen
>>> class Singleton(object):
... def __new__(cls, *args, **kwargs):
... if '_inst' not in vars(cls):
... cls._inst = type.__new__(cls, *args, **kwargs)
... return cls._inst
...
>>> class mycls (Singleton):
... pass
...
>>> a=mycls()
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
File "<interactive input>", line 4, in __new__
TypeError: type.__new__(mycls): mycls is not a subtype of type