[Python] __slots__ method


[Python] __slots__ method

slots 기본적으로 파이썬에서는 객체의 인스턴스 속성을 저장하기 위해서 dict 를 사용 하는데 이를 통해 런타임 중 속성을 변경할 수 있다. 하지만 dict 는 메모리를 낭비하는 경향이 있다. slots를 사용하는 경우 두가지 효과가 있다. 속성에 대한 빠른 접근 class Normal(object): pass class UsingSlots(object): __slots__ = ['name'] normal = Normal() use_slots = UsingSlots() def fn_set_get_delete(cls): def set_get_delete(): setattr(cls, 'name', 'foo var') getattr(cls, 'name..


원문링크 : [Python] __slots__ method