The ancient ConfigParser module available in the standard library 2.x has seen a major update in Python 3.2. This is a backport of those changes so that they can be used directly in Python 2.6 - 2.7.
To use configparser instead of ConfigParser, simply replace:
import ConfigParser
with:
import configparser
For detailed documentation consult the vanilla version at http://docs.python.org/py3k/library/configparser.html.
Why you'll love configparser
*
there's now one default ConfigParser class, which basically is the old SafeConfigParser with a bunch of tweaks which make it more predictable for users. Don't need interpolation? Simply use ConfigParser(interpolation=None), no need to use a distinct RawConfigParser anymore.
*
the parser is highly customizable upon instantiation supporting things like changing option delimiters, comment characters, the name of the DEFAULT section, the interpolation syntax, etc.
*
you can easily create your own interpolation syntax but there are two powerful implementations built-in (more info):
o the classic %(string-like)s syntax (called BasicInterpolation)
o a new ${buildout:like} syntax (called ExtendedInterpolation)
*
ConfigParser objects can now read data directly from strings and from dictionaries. That means importing configuration from JSON or specifying default values for the whole configuration (multiple sections) is now a single line of code. Same goes for copying data from another ConfigParser instance, thanks to its mapping protocol support.
*
many smaller tweaks, updates and fixes
|