config_loader.py 518 B

12345678910111213141516171819
  1. import json
  2. import os
  3. def load_config(config_name):
  4. """加载配置文件"""
  5. # 获取配置文件路径
  6. config_path = os.path.join(
  7. os.path.dirname(os.path.dirname(os.path.dirname(__file__))),
  8. "config",
  9. config_name
  10. )
  11. # 检查文件是否存在
  12. if not os.path.exists(config_path):
  13. raise FileNotFoundError(f"配置文件不存在: {config_path}")
  14. # 加载配置
  15. with open(config_path, 'r', encoding='utf-8') as f:
  16. return json.load(f)