这是我的方法:
def readConfigProperties(sectionName):
# Using Confir Parser : Import the package First : add interpreter too
config = configparser.RawConfigParser()
config.read('Path To Properties ')
details_dict = dict(config.items(sectionName))
print(details_dict)
return details_dict目前,我正在传递节名称,这工作得很好,但我想要加载之前场景的所有完整的属性文件一次。
发布于 2020-07-21 04:45:49
这样做如何:
all = {}
for section_name in config.sections():
for name, value in config.items(section_name):
all[name] =value发布于 2020-07-21 04:46:35
config.sections()将返回节的列表,例如,如果您希望将整个配置文件读取到嵌套字典中,则可以使用:
{name: dict(config.items(name)) for name in config.sections()}示例--来自输入文件:
[blah]
foo = bar
[baz]
quux = whatever这将为您提供:
{'blah': {'foo': 'bar'}, 'baz': {'quux': 'whatever'}}https://stackoverflow.com/questions/63003462
复制相似问题