, , class.
, reset , .
:
class Foo:
instance = None
def __init__(self, ...):
if type(self).instance is None:
type(self).instance = self
else:
raise RuntimeError("Only one instance of 'Foo' can exist at a time")
@classmethod
def reset(cls):
cls.instance = None
cls.instance = Foo(...)
, Foo.instance.
reset , , @classmethod.
reset, Foo.reset(), cls .
( ) , , Foo, reset .
, "" .
, reset, :
def reset(self):
self.__init__()
.
, __init__.
__init__ reset .
reset, .
, , , .
, " ", , , , .
, .
, ( " " ) , Foo , .