python读取配置文件.ini报错raise NoSectionError(section) from None configparser.NoSectionError: No section: ‘log’
我的配置文件:
读取配置文件代码:
from configparser import ConfigParser
1、实例化ConfigParser类
conf = ConfigParser()
2、读取配置文件
conf.read(“conf_ini”,encoding=‘utf-8’)
3、读取某一项配置值:get,全部都是字符串
value = conf.get(‘log’,“name”)
运行后报错:
raise NoSectionError(section) from None
configparser.NoSectionError: No section: ‘log’
原因:没读取到.ini配置文件
解决方法:
直接填写绝对路径