728x90
반응형
hasattr(object, attribute)는 object에 attribute 속성이 있으면 True, 없으면 False를 출력하는 함수를 이야기한다.
class example:
def __init__(self, x):
self.x =x
c = example(1)
print(c.x) # 1
print(hasattr(c, 'x')) # True
print(hasattr(c, 'y')) # False
주로 DL에서 속성이 있을 때 초기화 하는 용도로 사용한다.
728x90
반응형
'CS 지식 정리 > 개발기록' 카테고리의 다른 글
[python] fire 패키지 (0) | 2024.05.09 |
---|---|
'wget'은(는) 내부 또는 외부 명령, 실행할 수 있는 프로그램, 또는배치 파일이 아닙니다. (0) | 2023.11.26 |
OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized (0) | 2023.11.06 |
ERROR: Cannot find command 'git' - do you have 'git' installed and in your PATH? (0) | 2023.10.18 |
[python] AI class 기본 메서드 __init__, __len__, __getitem__ (0) | 2023.08.20 |
댓글