美文网首页大数据 爬虫Python AI Sql
解决python读取 的.ini 文件中有特殊符号 %

解决python读取 的.ini 文件中有特殊符号 %

作者: 一束荆棘 | 来源:发表于2019-11-27 18:17 被阅读0次

    在我们的项目中经常使用 .ini文件做配置文件,当我们的value中存在特殊符号时,使用Python读取value就会报错

    `[configparser.InterpolationSyntaxError:](configparser.interpolationsyntaxerror:) ``'%'` `must be followed by ``'%'` `or` `'('``, found: ``'%v='`
    
    

    解决问题的办法很简单,把

    cf = configparser.ConfigParser()
    

    换成

    cf =configparser.RawConfigParser()
    

    原因:

    Python的ConfigParser Module中定义了3个类对INI文件进行操作。分别是RawConfigParser、ConfigParser、SafeConfigParser。RawCnfigParser是最基础的INI文件读取类,ConfigParser、SafeConfigParser支持对%(value)s变量的解析

    相关文章

      网友评论

        本文标题:解决python读取 的.ini 文件中有特殊符号 %

        本文链接:https://www.haomeiwen.com/subject/lphmwctx.html