封装获取配置文件:
# config.ini
[logging]
name = zangai
level = DEBUG
filename = testlog.log
sh_level = DEBUG
fh_level = INFO
[env]
base_url = http://api.dsad.site:8000
[test_data]
username =
password =
[invest_user]
mobile=
pwd=
[test_admin]
mobile=
pwd=
[mysql]
host = api.lemonban.com
port = 3306
username =
password =
from configparser import ConfigParser
import os
from commons.handle_path import CONF_DIR
# handle_config
class Config(ConfigParser):
def __init__(self,conf_file):
super().__init__()
self.read(conf_file,encoding='utf-8')
conf=Config(os.path.join(CONF_DIR,'config.ini'))
print(conf.get("mysql", "host"))
print(conf.getint("mysql", "port"))