# -*- coding: utf-8 -*-
import os
from utils.reader import YamlReader
BASE_PATH = os.path.split(os.path.dirname(os.path.abspath(__file__)))[0]
CONFIG_FILE = os.path.join(BASE_PATH, 'config', 'config.yml')
# DATA_PATH = os.path.join(BASE_PATH, 'data')
LOG_PATH = os.path.join(BASE_PATH, 'log')
REPORT_PATH = os.path.join(BASE_PATH, 'report')
class Config(object):
def __init__(self, config=CONFIG_FILE):
self.config = YamlReader(config).data
def get(self, element, index=0):
"""用YamlReader读取返回的是一个list,第一项是默认的节。如果有多个节,可以传入index来获取。"""
return self.config[index].get(element)
def get_db_conf(self):
db_conf = self.get('database')
return '{engine}://{user}:{pwd}@{host}:{port}/{db}?charset={charset}'.format(**db_conf)
conf = Config() # default conf, parse config.yml
2018-11-26 python 配置模块
最新推荐文章于 2022-04-07 17:49:19 发布