在配置文件的每个部分中,我有相同选项的多个值。我想循环并运行相同的进程,每次为每个选项,这是可能的与ConfigParser?
[Section1][Section2]SameSectionOptionName: Value
SameSectionOptionName:价值
[Section3]SameSectionOptionName:价值
SameSectionOptionName:价值
SameSectionOptionName:价值
SameSectionOptionName:价值
等等
问候,谢谢你!
使用ConfigParser模块是不可能的。它使用不区分大小写的字典在内部存储配置,如果有多个相同的键,它将只提供最后遇到的值,例如:
config.ini
[SomeSection]
SomeOption: Value 1
SomeOption: Value 2
SomeOption: Value 3
控制台>>> import ConfigParser
>>> ConfigParser.ConfigParser()
<ConfigParser.ConfigParser instance at 0x10d4b91b8>
>>> c.read('config.ini')
['config.ini']
>>> c.get('SomeSection', 'SomeOption')
'Value 3'
>>> c.items('SomeSection')
[('someoption', 'Value 3')]