【轉載】Python中ConfigParser.InterpolationSyntaxError: '%' must be followed by '%' or '(', found: "%&'" 解決方案
阿新 • • 發佈:2018-12-09
原文連結:https://blog.csdn.net/s740556472/article/details/82889758
前言
在寫python程式讀取配置檔案的時候,遇到了一個錯誤,記錄下解決方案。
錯誤如下:
程式碼詳情
讀取read_ini.ini時由於我的ini檔案中內容如下:
當代碼執行到 ip_128 = cf.get(‘cmd’,‘10.10.111.1’)這行,丟擲了ConfigParser.InterpolationSyntaxError: ‘%’ must be followed by ‘%’ or ‘(’, found: "%&’"的錯誤。
大致意思是,因為ini的內容中包含了%號這種特殊符號。
解決方案
換一種方式進行讀取配置檔案
原本程式碼:cf= configparser.ConfigParser()
替換成:
cf = configparser.RawConfigParser()
報錯解決!
---------------------
作者:sy_y
來源:CSDN
原文:https://blog.csdn.net/s740556472/article/details/82889758
版權宣告:本文為博主原創文章,轉載請附上博文連結!