CLS (1) 썸네일형 리스트형 파이썬 간단한 싱글톤(singleton) 클래스 만들기 class test: pass t1 = test() t2 = test() print(t1) print(t2) 간단한 test 클래스를 만들고, t1 = test() 첫번째 테스트 객체 생성 t2 = test() 두번째 테스트 객체 생성 그 후, print 로 출력 해보니 할당된 주소가 나옵니다. 주소가 다르네요. 두개의 test 객체가 생성 되었습니다. class test: def __new__(cls, *args, **kwargs): if not hasattr(cls, "_ins"): print("CREATE TEST CLASS") cls._ins = super().__new__(cls) return cls._ins t1 = test() t2 = test() print(t1) print(t2) __ne.. 이전 1 다음