# coding:utf-8 import yaml #pip install pyyaml import os import json base_path = os.path.dirname(os.path.abspath(__file__)) conf_file= os.path.join(base_path,"db.yaml") def read_yaml(): #读取配置文件信息 try: f = open('db.yaml',encoding="utf-8") data = f.read() yaml_reader = yaml.safe_load(data) return yaml_reader except Exception as e: print("读取配置文件[{}]异常:{}".format(conf_file,e)) return {} if __name__ == "__main__": print(json.dumps(read_yaml(),indent=" "))
标签:__,读取,配置文件,python,yaml,path,os From: https://www.cnblogs.com/boye169/p/17485632.html