擅长:python、mysql、java
<p>您可以将分隔符从逗号(<code>,</code>)改为分号(<code>:</code>)还是使用等号(<code>=</code>)?在这种情况下<code>ConfigParser</code>将自动为您执行此操作。</p>
<p>例如,我在将逗号改为等于后分析了您的示例数据:</p>
<pre><code># urls.cfg
[URLs]
Google=www.google.com
Hotmail=www.hotmail.com
Yahoo=www.yahoo.com
# Scriptlet
import ConfigParser
filepath = '/home/me/urls.cfg'
config = ConfigParser.ConfigParser()
config.read(filepath)
print config.items('URLs') # Returns a list of tuples.
# [('hotmail', 'www.hotmail.com'), ('google', 'www.google.com'), ('yahoo', 'www.yahoo.com')]
</code></pre>