python field函数
from dataclasses import field, dataclass@dataclass class Employ:name: strage: int = field(default=30)position: str = field(default='Developer', metadata={'description': 'the job title'})zhangsan = Employ(name='zhangsan') print(zhangsan)
import traceback from dataclasses import dataclass@dataclass class Retangle:width: intheight: intdef __post_init__(self):if self.width < 0 or self.height < 0:raise ValueError('width or height invalid')try:retangle = Retangle(width=-1, height=2) except Exception:traceback.print_exc()
Please call me JiangYouDang!
