class Singleton(object): def __new__(type): if not '_the_instance' in type.__dict__: type._the_instance = object.__new__(type) return type._the_instancea=Singleton()a.toto = 12b=Singleton()print b.totoprint id(a),id(b) # the same !!print a print b## now lets inherit from it:class Main(Singleton): def __init__(self): Singleton.__init__(self) ## only init if not done already #if not hasattr(self, "x"): # self.x =4test = Main()print test#print test.x test.x = 5print test.xtest2 = Main()print test2print test2.x