如何在 ConfigObj 中编写注释?
我正在使用 python 2.4.3 和 ConfigObj 4.7
我在 ConfigObj 文档中没有看到任何方法。
最佳答案
经过一些测试,我发现你也可以为每个部分使用评论属性,这里有一个小例子:
filename = 'test.ini'
config = ConfigObj(filename)
config['section1'] = {
'key1': 'value1'
}
config['section2'] = {
'key2': 'value2'
}
config['section1'].comments = {
'key1': ['Comment before keyword1',]
}
config['section1'].inline_comments = {
'key1': 'Inline comment'
}
config.comments['section2'] = ['Comment before section2']
config.write()
这应该生成以下文件:
[section1]
# Comment before keyword1
key1 = value1 # Inline comment
# Comment before section2
[section2]
key2 = value2
关于python - 有什么办法可以在 python 中使用 configobj 编写注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43867144/