SINGLETON factory

You can define Singleton class manually, but if you want to create multiple different Singleton classes on the fly then you can use the function below :

#Factory : to create Singleton classes
def singleton(new_klass, klass): 

	def new(cls, *args, **kvargs):
		if not hasattr(cls, 'instance'):
			cls.instance = klass(*args, **kvargs)
		return cls.instance

	globals()[new_klass] = type(new_klass, (object,), {'__new__' : new})