configparser是python 读写ini配置文件的一个开源库,具体的安装过程这里就不用一一描述。直接上代码来说明用途

#!/user/bin/env python
#coding=utf-8

from configparser import ConfigParser
from framework.logger import Logger

logger = Logger(logger="configUtil").getlog()

'''配置文件解析工具类'''
class configUtil:

def __init__(self,fileName):
    '''初始化'''
    try:
        self.config = ConfigParser()
        self.config.read(fileName,encoding='utf-8')
    except:
        # logger.exception('IO异常,请检查配置!')
        pass

def get(self,section,option):
    return self.config.get(section,option)

if name == 'main':
config = configUtil(r'E:\autoTest\rcpAutoTest_20190920\config\config.ini')
print(config)
host = config.get('sitmysqlconf', 'host')
print(host)