ParsingError: ConfigParser Python
ParsingError: ConfigParser Python
我用的是configparser to read ini file. However, I am getting ParsingError,如下图:
[line 2]: ' % ---------------- File created by User ----------------------\n'
[line 9]: ' % ---------------------------------------------------------------------------\n'
[line 11]: ' % ---------------------------------------------------------------------------\n'
我不能使用选项 "allow_no_value=True",因为第 9 行和第 11 行相同并且在文档中。
示例文档如下:
' % ---------------- File created by User ----------------------\n'
[OrderID]
orderName = Ord1
orderNumber = Ord2#02
有没有办法解析文档?我目前使用的代码如下:
import configparser
config = configparser.ConfigParser()
config.read(path,encoding='cp1250')
谢谢
来自 configparser
的文档:“配置解析器允许大量自定义。”
特别是,您可以指定 '
引入注释行。
import configparser
config = configparser.ConfigParser(comment_prefixes=("#", ";", "'"))
config.read(path, encoding='cp1250')
参见:https://docs.python.org/3/library/configparser.html#customizing-parser-behaviour
我用的是configparser to read ini file. However, I am getting ParsingError,如下图:
[line 2]: ' % ---------------- File created by User ----------------------\n'
[line 9]: ' % ---------------------------------------------------------------------------\n'
[line 11]: ' % ---------------------------------------------------------------------------\n'
我不能使用选项 "allow_no_value=True",因为第 9 行和第 11 行相同并且在文档中。
示例文档如下:
' % ---------------- File created by User ----------------------\n'
[OrderID]
orderName = Ord1
orderNumber = Ord2#02
有没有办法解析文档?我目前使用的代码如下:
import configparser
config = configparser.ConfigParser()
config.read(path,encoding='cp1250')
谢谢
来自 configparser
的文档:“配置解析器允许大量自定义。”
特别是,您可以指定 '
引入注释行。
import configparser
config = configparser.ConfigParser(comment_prefixes=("#", ";", "'"))
config.read(path, encoding='cp1250')
参见:https://docs.python.org/3/library/configparser.html#customizing-parser-behaviour