python读取yaml文件夹

python读取yaml文件夹

import yaml
import os
yolov5_yaml = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))),"D:/pychpy/config/yolov5s.yaml")
#config/yolov5s.yaml
#'''初始化'''
# 载入配置文件
class_id = 56
with open(yolov5_yaml, 'r', encoding='utf-8') as f:
    yolov5name = yaml.load(f.read(), Loader=yaml.SafeLoader)
print(yolov5name['class_name'][class_id])

你可能感兴趣的:(python,python,开发语言)