python实战 yml文件解析

Last updated on November 22, 2024 pm

🧙 Questions

☄️ Ideas

import sys
import os
import yaml

# 获取配置文件路径
config_file_name = 'config.yml'
if getattr(sys, 'frozen', False):
    config_file_path = os.path.join(os.path.dirname(sys.executable), config_file_name)
elif __file__:
    config_file_path = os.path.join(os.path.dirname(__file__), config_file_name)

# 获取配置文件内容
config_file = open(config_file_path, mode='r', encoding='utf-8')
config = yaml.load(config_file, Loader=yaml.FullLoader)

# 解析yml文件
# hexo:
#   post_project_dir: xxx
blogs_path = config['hexo']['post_project_dir']
categories = config['hexo']['categories']

python实战 yml文件解析
https://ispong.isxcode.com/pytorch/python/python实战 yml文件解析/
Author
ispong
Posted on
March 24, 2022
Licensed under