1234567891011121314151617181920212223242526 |
- 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()
- for i in tg:
- mmode = i.split("_")[1]
- print(mmode)
|