我在 .ini 文件中有这样的东西
[General]
verbosity = 3 ; inline comment
[Valid Area Codes]
; Input records will be checked to make sure they begin with one of the area
; codes listed below.
02 ; Central East New South Wales & Australian Capital Territory
03 ; South East Victoria & Tasmania
;04 ; Mobile Telephones Australia-wide
07 ; North East Queensland
08 ; Central & West Western Australia, South Australia & Northern Territory
但是,我遇到的问题是内联注释在该key = value
行中有效,但在key
没有值的行中无效。这是我创建 ConfigParser 对象的方式:
>>> import ConfigParser
>>> c = ConfigParser.SafeConfigParser(allow_no_value=True)
>>> c.read('example.ini')
['example.ini']
>>> c.get('General', 'verbosity')
'3'
>>> c.options('General')
['verbosity']
>>> c.options('Valid Area Codes')
['02 ; central east new south wales & australian capital territory', '03 ; south east victoria & tasmania', '07 ; north east queensland', '08 ; central & west western australia, south australia & northern territory']
如何设置配置解析器以便内联注释适用于这两种情况?