본문 바로가기

파이썬21

KISA 128bit SEED CBC 암호화 복호화 결제 관련 외부 API를 연동할 때, 해당 암호화 방식을 사용해야 하는 경우가 있습니다.파이썬 코드를 제공하는 곳을 아직 찾지 못해 PHP 코드를 참고하여 구현했습니다.# pip install cryptographyfrom cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modesfrom cryptography.hazmat.primitives import paddingfrom cryptography.hazmat.backends import default_backendimport base64class SEEDCBC: def __init__(self, iv, key): self.iv = bytes(iv, 'utf-8') .. 2024. 4. 16.
map(), filter(), pipe()를 활용하여 데이터 다루기 map(), filter() 함수는 리스트 안의 데이터를 내가 원하는 대로 추출하거나 변형시킬 수 있습니다.def square(num): return num**2number_list = [1, 2, 3, 4, 5]result = map(square, number_list)print(result) # # for loop -> [1, 4, 9, 16, 25]print(list(result)) # [1, 4, 9, 16, 25]# 람다result = list(map(lambda x: x**2, number_list))print(result) # [1, 4, 9, 16, 25]map()의 리턴 데이터 타입은 map objectfilter() 또한 filter object 리스트 to 리스트를 통해 DB에.. 2024. 4. 8.
Pydantic을 활용한 JSON, dict 다루기 Pydantic을 통해 Object를 JSON으로 Serialization 하거나JSON을 Object로 Deserialization 할 수 있습니다. import jsonplayer = { "team": "MTU", "name": "박지성",}json_str = json.dumps(player, ensure_ascii=False).replace(' ', '')print(json_str)json 라이브러리를 통해 dict를 json으로 변경공백을 지워줘야 합니다. from pydantic import BaseModelclass Player(BaseModel): team: str name: strplayer = { "team": "MTU", "name": "박지성",}pla.. 2024. 4. 1.
UploadFile, 이미지 form-data 이미지 등의 파일을 업로드할 때는 form-data로 데이터를 받습니다."file": { "filename": "test.jpg", "file": { "_file": {}, "_max_size": 1048576, "_rolled": false, "_TemporaryFileArgs": { "mode": "w+b", "buffering": -1, "suffix": null, "prefix": null, "encoding": null, "newline": null, "dir": null, "er.. 2024. 3. 28.