【大爆炸】读取配置文件 yaml

# -*- coding: utf-8 -*-
"""
-------------------------------------------------
   File Name:     conf.py
   Description :   读取当前文件上级目录conf 内hcs_conf.yaml的内容,返回yaml 对象
   Author :       jiaoyaxiong
   date:          2019/7/22
-------------------------------------------------
   Change Activity:
                   2019/7/22:
-------------------------------------------------
"""
__author__ = 'jiaoyaxiong'

import yaml
import os
import platform

def get_conf():
    # 当前目录:os.path.abspath(os.path.dirname(__file__))
    current_path = os.path.abspath(os.path.dirname(__file__))
    if str(platform.system()) == "Windows":
        f = open(os.path.dirname(current_path)+os.sep+"conf"+os.sep+"hcs_conf.yaml")
    #需要修改为读取固定位置的文件
    else:
        f =open("/hsync/conf/hcs_conf.yaml")
    cfg = yaml.load(f.read(), Loader=yaml.FullLoader)
    f.close()
    return cfg

if __name__ == "__main__":
    print get_conf()["global"]["base_log_path"]

  

posted @ 2021-03-04 18:07  峡谷恶霸  阅读(94)  评论(0编辑  收藏  举报