In python, is it better that using the singleton pattern instead of using global variable?
class Singleton(type):
def __call__(self, *args, **kwargs):
if 'instance' not in self.__dict__:
self.instance = super(Singleton, self).__call__(*args, **kwargs)
return self.instance
or just make a global variable:
SINGLETON_VARIABLE = None
def getSingleton():
if SINGLETON is None:
SINGLETON_VARIABLE = SOME_ININ_CLASS()
return SINGLETON_VARIABLE
Is it necessary to complicate the life to make a singleton pattern? Thank you in advance.