forked from ancoka/hw_seckill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
27 lines (22 loc) · 907 Bytes
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# -*- coding: utf-8 -*-
# !/usr/bin/python
from configparser import ConfigParser
from loguru import logger
class Config:
def __init__(self, filename, encoding="utf-8"):
logger.info("开始解析配置文件")
self.filename = filename
self.encoding = encoding
self.config = ConfigParser()
self.config.read(filename, encoding)
logger.info("结束解析配置文件")
def get(self, section, option, default_value=None):
if default_value is None:
return self.config.get(section, option)
else:
return self.config.get(section, option, fallback=default_value)
def getboolean(self, section, option, default_value=None):
if default_value is None:
return self.config.getboolean(section, option)
else:
return self.config.getboolean(section, option, fallback=default_value)