configparser.NoSectionError: No section: 'mysql'

ConfigParser跨目录读取配置文件,报错如下:

configparser.NoSectionError: No section: 'mysql'

使用绝对路径

import os
path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
print(path)
cp = ConfigParser()
cp.read(path+"/config/db.conf")
发布了89 篇原创文章 · 获赞 79 · 访问量 10万+

猜你喜欢

转载自blog.csdn.net/L_15156024189/article/details/89366797