擅长:python、mysql、java
<pre><code>import ConfigParser
config = ConfigParser.ConfigParser()
config.add_section('URLs')
config.set('URLs', 'Google', 'www.google.com')
config.set('URLs', 'Yahoo', 'www.yahoo.com')
with open('example.cfg', 'wb') as configfile:
config.write(configfile)
config.read('example.cfg')
config.items('URLs')
# [('google', 'www.google.com'), ('yahoo', 'www.yahoo.com')]
</code></pre>
<p><a href="http://docs.python.org/library/configparser.html" rel="nofollow noreferrer">The documentation mentions</a>:</p>
<blockquote>
<p>The ConfigParser module has been
renamed to configparser in Python 3.0.
The 2to3 tool will automatically adapt
imports when converting your sources
to 3.0.</p>
</blockquote>