[Python] __new__ method
·
Python/Python
파이썬 Magic Method https://docs.python.org/ko/3.7/reference/datamodel.html#special-method-names new 인스턴스 생성시 호출되며 Static method 이다. 일반적인 구현은 super().new(cls) 로 인스턴스 생성후 Return 전에 필요한 작업을 함 만약 인스턴스를 Return 하지 않는다면 init 은 호출되지 않는다. class Sample(object): def __new__(cls, *args, **kwargs): print('new', args, kwargs) this = super().__new__(cls) cls.args = args cls.kwargs = kwargs return this def __init..