![](/img/trans.png)
[英]How to remove a section from an ini file using Python ConfigParser?
[英]ConfigParser getting value from INI file with section and subsection as shown below
我有以下类型的INI文件
[section1][subsection1]
port=989
[section1][subsection2]
somethign=somethign
我正在使用Python的ConfigParser解析INI文件,但无法弄清楚如何从上述INI文件中获取数据。
下面的代码用于在INI文件类似时获取值
[section1]
port=908
[section2]
ss=ss
config = ConfigParser.RawConfigParser()
config.read(INI_File)
mIp = config.get('section1','port')
请不要建议我更改INI文件格式:)
谢谢
似乎ConfigParser忽略了子节。 如果您绝对需要这些小节,则可以尝试使用其他解析器,例如ConfigObj( PyPi , tutorial )
这是一个老问题的答案: https : //stackoverflow.com/a/3008051/49412
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.