class Singleton(object):
def __new__(cls, *args, **kwargs):
if '_inst' not in vars(cls):
cls._inst = super(Singleton, cls).__new__(cls, *args, **kwargs)
return cls._inst
class A(Singleton):
def __init__(self, s):
self.s = s
print("__init__")
def __str__(self):
return self.s
objA = A("spam")
print id(objA)
print objA.s
objB = A("eggs")
print id(objB)
print objB.s
print objA.s