ConfigParser.InterpolationSyntaxError: ‘%‘ must be followed by ‘%‘ or ‘(‘, found: “%&‘“

Python使用configparser读取配置文件(config.ini)过程中,报异常信息:ConfigParser.InterpolationSyntaxError: '%' must be followed by '%' or '(', found: "%&'"

目录

1、配置文件 

2、核心代码

3、 问题解决


1、配置文件 #

#  定义cmd分组
[cmd]
startServer=adb start-server

2、核心代码#

import configparser
 
#  实例化configParser对象
config = configparser.ConfigParser()

# -get(section,option)得到section中option的值,返回为string类型
print(config.get('cmd', 'startserver'))

3、 问题解决#

将configparser.ConfigParser()替换成:configparser.RawConfigParser() 即可解决这个问题。

import configparser
 
#  实例化configParser对象
config = configparser.RawConfigParser()

# -get(section,option)得到section中option的值,返回为string类型
print(config.get('cmd', 'startserver'))

作者:YangRoc

出处:https://www.cnblogs.com/YangRoc/p/17186557.html

版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。

posted @   Roc-xb  阅读(257)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)

易微帮源码


易微帮官网

more_horiz
keyboard_arrow_up dark_mode palette
选择主题
menu
点击右上角即可分享
微信分享提示