123456789101112131415161718192021222324 |
- import yaml
- from utils.project_paths import config_dir
- class TopicGroup:
- def __init__(self, config_path=f"{config_dir}/topic_map.yaml"):
- with open(config_path, "r") as f:
- data = yaml.safe_load(f)
- self.topics = data.get("topics", []) # 直接获取 topic 列表
- def __iter__(self):
- """支持迭代遍历 topics"""
- return iter(self.topics)
- def __len__(self):
- return len(self.topics)
- def __str__(self):
- return str(self.topics)
- if __name__ == '__main__':
- tg = TopicGroup()
- print(tg)
|