File size: 1,393 Bytes
7da2ecb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | """
file: config.py
date: 2026/02/15
brief: JSON κΈ°λ° μ€μ νμΌ λ‘λ μ νΈλ¦¬ν°
λ³Έ λͺ¨λμ νλ‘μ νΈ μ λ°μμ μ¬μ©λλ μ€μ (JSON) νμΌμ
νμ΄μ¬ λμ
λ리 ννλ‘ λ‘λνκΈ° μν κ³΅ν΅ μ νΈ ν¨μλ€μ μ 곡νλ€.
νΉμ§:
- UTF-8 μΈμ½λ©μ λͺ
μμ μΌλ‘ μ¬μ©
- μ€μ νμΌμ ꡬ쑰λ ν€μ λν κ²μ¦μ μννμ§ μμ
- κ° step(step1/2/3) μ€ν¬λ¦½νΈμμ λμΌν λ°©μμΌλ‘ μ¬μ¬μ©λ¨
----------------------------------------------------------------------
Version Date Comment
--------- ---------- ----------------------------------------------
"""
import json
from typing import Any, Dict
def load_config(path: str) -> Dict[str, Any]:
"""
JSON νμμ μ€μ νμΌμ λ‘λνμ¬ λμ
λλ¦¬λ‘ λ°ννλ€.
Parameters
----------
path : str
λ‘λν μ€μ νμΌ(JSON)μ κ²½λ‘
Returns
-------
dict[str, Any]
JSON νμΌ λ΄μ©μ κ·Έλλ‘ λ΄μ μ€μ λμ
λ리
Raises
------
FileNotFoundError
μ§μ ν κ²½λ‘μ νμΌμ΄ μ‘΄μ¬νμ§ μλ κ²½μ°
json.JSONDecodeError
JSON νμμ΄ μ¬λ°λ₯΄μ§ μμ κ²½μ°
UnicodeDecodeError
νμΌ μΈμ½λ©μ΄ UTF-8μ΄ μλ κ²½μ°
"""
with open(path, "r", encoding="utf-8") as f:
cfg = json.load(f)
return cfg
|