<p>我在一个.in I文件里有这样的东西</p>
<pre><code>[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
</code></pre>
<p>但是,我有一个问题,内联注释在<code>key = value</code>行中工作,而不是在没有值行的<code>key</code>中工作。下面是创建ConfigParser对象的方法:</p>
<pre><code>>>> 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']
</code></pre>
<p>如何设置配置分析器,以便内联注释对这两种情况都有效?</p>