1、新增配置文件getConf.py
import configparser, os
class Base_confi():
"""默认读取conf_data下的conf.ini文件,初始化读取conf.ini配置文件"""
def __init__(self):
self.configfile_path = os.path.join(os.path.dirname(__file__),'..','config/conf.ini')
self.conf = configparser.ConfigParser()
self.conf.read(self.configfile_path)
"""获取指定节点下指定option的值,返回为字符串类型"""
def config_get(self, title, value):
return self.conf.get(title, value)
"""返回conf.ini文件路径"""
def config_path(self):
return self.configfile_path
"""修改conf.ini文件数据,如果section不存在的话,先进行判断然后进行添加再修改"""
def config_modify(self, section, option, value):
if not self.conf.has_section(section):
self.conf.add_section(section)
self.conf.set(section, option, value)
with open(self.configfile_path,"w")as f:
self.conf.write(f)
if __name__ =='__main__':
a = Base_confi()
print(a.config_get("site","url"))
2、新增conf.ini文件,如下