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配置文件
解决方法:
直接填写绝对路径
本文介绍了如何在Python中使用ConfigParser处理ini配置文件时遇到'NoSectionError: No section: 'log''的问题,重点在于提供了解决方案——确保正确读取绝对路径的配置文件。
643

被折叠的 条评论
为什么被折叠?



