使用 configobj 来逐一读取完整的部分
我正在使用 configobj 读取配置文件,如下所示。
[default]
PROP1 = "12345"
PROP2 = "abcde"
[section1]
PROP1 = "56789"
PROP2 = ""
[section2]
PROP1 = ""
PROP2 = ""
我的目标是先阅读章节列表,然后将每个章节放入字典中。如果不存在值,我必须替换为默认值。假设第 2 节 - PROP1 将变为“12345”。我一直在研究 configobj 来读取字典对象的一部分,但看起来没有函数/方法可以做到这一点。有什么帮助吗?
谢谢乌玛帕蒂
I am using configobj to read a config file as below.
[default]
PROP1 = "12345"
PROP2 = "abcde"
[section1]
PROP1 = "56789"
PROP2 = ""
[section2]
PROP1 = ""
PROP2 = ""
I aim to read the list of sections first and then get each section onto a dictionary. I have to replace with default values if no value is present. say section2 - PROP1 will become "12345". I have been looking at configobj to read just a section onto a dictionary object, but it looks like there is no function/method to do it. Any help?
Thanks
Umapathy
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您读取配置文件时,configobj 会将其转换为字典。
When you read your config file, configobj will convert it into a dictionary for you.