Класс-синглетон


# Перегрузка конструктора

class Singleton(object):
    _instance = None
    def __new__(self, *args, **kwargs):
        if not self._instance:
            self._instance = super(
                Singleton, self).__new__(self, *args, **kwargs)
        return self._instance


if __name__ == '__main__':
    s1=Singleton()
    s2=Singleton()
    if (id(s1)==id(s2)):
        print("Same")
    else:
        print("Different")