728x90
처음 보는 거라 처음에 굉장히 당황해서 남겨 놓는다.
python3.7 부터 생긴 기능인 것 같은데
dataclass decorator와 __post_init__을 사용해서 디폴트값을 설정할 수 가 있고, overidding을 계속 안해줘도 되는 것 같다.
디버깅을 해도 이부분은 확인이 안되서 난감했는데, 좋은 기능이라 생각하고 메모
from dataclasses import dataclass, field
@dataclass
class Book :
n_d: int = 8
n_a: int = 8
n_steps: int = 3
def __post_init__(self,):
self.full = self.n_d + self.n_a
c = Book()
print(c.n_d)
print(c.full)
c = Book(n_d=10,n_a=20)
print(c.n_d)
print(c.full)'분석 Python > 구현 및 자료' 카테고리의 다른 글
| numpy에서 dict을 이용해서 값을 바꾸는 방법 (2) | 2021.06.06 |
|---|---|
| tqdm) print대신에 tqdm을 이용해서 logging 방법 (0) | 2021.05.15 |
| [Python] Icecream 패키지를 사용하여 디버깅하기 (0) | 2021.01.16 |
| [Python] itertools (0) | 2021.01.01 |
| [Python] 적절한 샘플 사이즈를 찾아주는 코드 (0) | 2021.01.01 |