파이썬 스페셜 메서드 __getattribute__ 질문입니다.
조회수 491회
파이썬 객체 공부하다 보니 이해가 안되는 부분이 있어 질문드립니다.
class Test:
a = 1
def __getattribute__(self, name):
return 2
test = Test()
위 코드를 실행한 후 dir(Test
)를 실행하면 아래처럼 예상한 결과가 나오는데,
dir(test)
로 하면 빈 리스트가 나옵니다.
>>> dir(Test)
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'a']
>>> dir(test)
[]
__getattribute__
때문에 그런 것 같은데 자세한 설명 부탁 드립니다.^
-
(•́ ✖ •̀)
알 수 없는 사용자
댓글 입력