Tag Archives: python

[python] 모델(VO) 클래스 정의 샘플

By | 3월 4, 2022

환경 python 3.9 pydantic 1.9.0 sqlalchemy 1.4.31 fastapi 0.73.0 소스 # 리스트 내 요소 모델 class Prod(BaseModel): field1: Optional[str] field2: Optional[int] field3: Optional[Union[str, List[str]]] # 두 가지 타입을 받을 수 있도록 Union 처리 # 리스트 모델 class TestModel(BaseModel): site_id: Optional[int] update_time: Optional[datetime] alias: Optional[str] path: Optional[str] prod_list: Optional[List[Prod]] # 목록(리스트,List)형 파라미터 consume # DB 모델… Read More »

[python] hex encode/decode 유틸 샘플

By | 3월 4, 2022

환경 python 3.9 소스 """ 평문을 인수로 받아서 hex encoded string을 리턴한다. """ @staticmethod def encode_hex(src: str): if not src: return '' return src.encode('utf-8').hex() """ hex encoded string을 인수로 받아서 평문을 리턴한다. """ @staticmethod def decode_hex(enc: str): if not enc: return '' return bytearray.decode(bytearray.fromhex(enc))