본문 바로가기
728x90

Python3

[python] fire 패키지 딥러닝 코드에서 많이 쓰이는 fire 패키지. 계속 정리해야겠다는 마음은 가지고 있었으나 귀찮고 이미 안 것 같은데 계속 까먹어서 이번에 간단하게 메모해 놓기로 했다. fire 패키지는 몯느 객체를 command line interface로 만들어주는 것이라고 한다.Command line interace(CLI)가 뭐냐?Command Line Interface(CLI)는 사용자가 텍스트 명령을 입력하여 컴퓨터와 상호 작용하는 인터페이스로 Graphic User Interface(GUI)와 대비된다. CLI는 주로 키보드를 통해 명령어를 입력하고, 시스템은 텍스트로 응답한다. 만약 다음과 같은 함수가 있다고 가정하자.import firedef Hello(name): return "Hello {name}!".. 2024. 5. 9.
[python] hasattr(object, attribute) object에 attribute 속성이 있는지 참/거짓 여부 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에서 속성이 있을 때 초기화 하는 용도로 사용한다. 2023. 11. 12.
[python] AI class 기본 메서드 __init__, __len__, __getitem__ AI Dataset을 정의할 때 흔히 __init__, __len__, __getitem__ 3가지를 많이 쓴다. 기본적으로 class에 내장되어 있는 메서드로서 한 번 메서드에 대해서 알아보자. __init__ 클래스를 생성할 때 실행되는 생성자 __len__ 원소의 개수를 셀 때 접근되는 메서드 __getitem__ 인덱스에 접근할 때 호출되는 메서드 class Test: def __init__(self): print("TEST 함수 실행") self.numbers = [i for i in range(10)] def __len__(self): print("__len__ 메서드 실행") return len(self.numbers) def __getitem__(self, idx): print("__get.. 2023. 8. 20.
728x90