"""配置与通用工具。""" DEFAULT_CONFIG = {"max_quantity": 99, "currency": "CNY"} def load_config(path: str = None) -> dict: """读配置;没有文件就返回默认值,保证示例零依赖可跑。""" cfg = dict(DEFAULT_CONFIG) if not path: return cfg with open(path, "r", encoding="utf-8") as f: for line in f: line = line.strip() if not line or line.startswith("#") or "=" not in line: continue k, v = line.split("=", 1) cfg[k.strip()] = int(v) if v.strip().isdigit() else v.strip() return cfg