【发布时间】:2012-10-12 06:42:22
【问题描述】:
我需要在 runtime 通过 Python 中的ConfigParser 库生成的配置文件中写一些注释。
我想写一个完整的描述性评论,例如:
########################
# FOOBAR section
# do something
########################
[foobar]
bar = 1
foo = hallo
代码应如下所示:
我同时插入注释和配置选项。
import ConfigParser
config = ConfigParser.ConfigParser()
config.insert_comment("##########################") # This function is purely hypothetical
config.insert_comment("# FOOBAR section ")
....
config.add_section('foobar')
config.set('foobar', 'bar', '1')
config.set('foobar', 'foo', 'hallo')
【问题讨论】:
标签: python comments configparser