ConfigParser getting value from INI file with sect

2019-07-14 07:26发布

I have a following type of INI file

[section1][subsection1]
port=989
[section1][subsection2]
somethign=somethign 

I am using ConfigParser of Python to parse the INI file but I am not able to figure it out on how to get the data from the above kinda INI file.

the below code is for getting the value when INI file is like

[section1]
port=908
[section2]
ss=ss

config = ConfigParser.RawConfigParser()
config.read(INI_File)
mIp =  config.get('section1','port')

Please don't suggest me to change the INI file format :)

thank you

1条回答
聊天终结者
2楼-- · 2019-07-14 07:51

It appears that ConfigParser ignores subsections. If you absolutely need subsections, you may want to try alternative parsers such as ConfigObj (PyPi, tutorial)

And here is an answer to an older question: https://stackoverflow.com/a/3008051/49412

查看更多
登录 后发表回答