forked from huaisha1224/jd-assistant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
29 lines (20 loc) · 774 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
28
29
# -*- coding: utf-8 -*-
import os
import configparser
class Config(object):
def __init__(self, config_file='config.ini'):
self._path = os.path.join(os.getcwd(), config_file)
if not os.path.exists(self._path):
raise FileNotFoundError("No such file: config.ini")
self._config = configparser.ConfigParser()
self._config.read(self._path, encoding='utf-8')
def get(self, section, name, strip_blank=True, strip_quote=True):
s = self._config.get(section, name)
if strip_blank:
s = s.strip()
if strip_quote:
s = s.strip('"').strip("'")
return s
def getboolean(self, section, name):
return self._config.getboolean(section, name)
global_config = Config()