<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!--Converted with LaTeX2HTML 98.2 beta6 (August 14th, 1998)
original version by:  Nikos Drakos, CBLU, University of Leeds
* revised and updated by:  Marcus Hennecke, Ross Moore, Herb Swan
* with significant contributions from:
  Jens Lippmann, Marek Rouchal, Martin Wilck and others -->
<HTML>
<HEAD>
<TITLE>5.7 ConfigParser --
Configuration file parser</TITLE>
<META NAME="description" CONTENT="5.7 ConfigParser --
Configuration file parser">
<META NAME="keywords" CONTENT="lib">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<LINK REL="STYLESHEET" HREF="lib.css">
<LINK REL="next" HREF="module-fileinput.html">
<LINK REL="previous" HREF="module-array.html">
<LINK REL="up" HREF="misc.html">
<LINK REL="next" HREF="ConfigParser-objects.html">
</HEAD>
<BODY bgcolor="#ffffff">
<div class=navigation>
<table align=center width="100%" cellpadding=0 cellspacing=2>
<tr>
<td><A HREF="ConfigParser-objects.html"><img width=32 height=32 align=bottom border=0 alt="next"
 src="../icons/next.gif"></A></td>
<td><A HREF="misc.html"><img width=32 height=32 align=bottom border=0 alt="up"
 src="../icons/up.gif"></A></td>
<td><A HREF="module-array.html"><img width=32 height=32 align=bottom border=0 alt="previous"
 src="../icons/previous.gif"></A></td>
<td align=center bgcolor="#99CCFF" width="100%">
 <b class=title>Python Library Reference</b></td>
<td><A HREF="contents.html"><img width=32 height=32 align=bottom border=0 alt="contents"
 src="../icons/contents.gif"></A></td>
<td><a
 href="modindex.html"><img width=32 height=32 align=bottom border=0 alt="modules"
 src="../icons/modules.gif"></a></td>
<td><A HREF="genindex.html"><img width=32 height=32 align=bottom border=0 alt="index"
 src="../icons/index.gif"></A></td>
</tr></table><b class=navlabel>Next:</b> <span class=sectref><A HREF="ConfigParser-objects.html">5.7.1 ConfigParser Objects</A></span>
<b class=navlabel>Up:</b> <span class=sectref><A HREF="misc.html">5. Miscellaneous Services</A></span>
<b class=navlabel>Previous:</b> <span class=sectref><A HREF="module-array.html">5.6 array  </A></span>
<br><hr></div>
<!--End of Navigation Panel-->

<H1><A NAME="SECTION007700000000000000000">
5.7 <tt class=module>ConfigParser</tt> --
         Configuration file parser</A>
</H1>

<P>


<P>
This module defines the class <tt class=class>ConfigParser</tt>. The
<tt class=class>ConfigParser</tt> class implements a basic configuration file
parser language which provides a structure similar to what you would
find on Microsoft Windows INI files.  You can use this to write Python 
programs which can be customized by end users easily.

<P>
The configuration file consists of sections, lead by a
"<tt class=samp>[section]</tt>" header and followed by "<tt class=samp>name: value</tt>" entries,
with continuations in the style of <span class=rfc><a name="rfcref-41249"
href="http://info.internet.isi.edu/in-notes/rfc/files/rfc822.txt">RFC 822</a></span>.  The optional values 
can contain format strings which refer to other values in the same
section, or values in a special <tt>DEFAULT</tt> section.  Additional
defaults can be provided upon initialization and retrieval.  Lines
beginning with "<tt class=character>#</tt>" are ignored and may be used to provide
comments.

<P>
For example:

<P>
<dl><dd><pre class=verbatim>
foodir: %(dir)s/whatever
</pre></dl>

<P>
would resolve the "<tt class=samp>%(dir)s</tt>" to the value of dir. All reference
expansions are done late, on demand.

<P>
Intrinsic defaults can be specified by passing them into the
<tt class=class>ConfigParser</tt> constructor as a dictionary.  Additional defaults
may be passed into the <tt class=method>get</tt> method which will override all
others.

<P>
<dl><dt><b><a name="l2h-796"><tt class=class>ConfigParser</tt></a></b> (<big>[</big><var>defaults</var><big>]</big>)
<dd>
Return a new instance of the <tt class=class>ConfigParser</tt> class.  When
<var>defaults</var> is given, it is initialized into the dictionairy of
intrinsic defaults.  They keys must be strings, and the values must be 
appropriate for the "<tt class=samp>%()s</tt>" string interpolation.  Note that
<var>__name__</var> is always an intrinsic default; it's value is the 
section name.
</dl>

<P>
<dl><dt><b><a name="l2h-797"><tt class=exception>NoSectionError</tt></a></b>
<dd>
Exception raised when a specified section is not found.
</dl>

<P>
<dl><dt><b><a name="l2h-798"><tt class=exception>DuplicateSectionError</tt></a></b>
<dd>
Exception raised when mutliple sections with the same name are found.
</dl>

<P>
<dl><dt><b><a name="l2h-799"><tt class=exception>NoOptionError</tt></a></b>
<dd>
Exception raised when a specified option is not found in the specified 
section.
</dl>

<P>
<dl><dt><b><a name="l2h-800"><tt class=exception>InterpolationError</tt></a></b>
<dd>
Exception raised when problems occur performing string interpolation.
</dl>

<P>
<dl><dt><b><a name="l2h-801"><tt class=exception>MissingSectionHeaderError</tt></a></b>
<dd>
Exception raised when attempting to parse a file which has no section
headers.
</dl>

<P>
<dl><dt><b><a name="l2h-802"><tt class=exception>ParsingError</tt></a></b>
<dd>
Exception raised when errors occur attempting to parse a file.
</dl>

<P>

<p><hr>
<!--Table of Child-Links-->


<UL>
<LI><A NAME="tex2html1735"
 HREF="ConfigParser-objects.html">5.7.1 ConfigParser Objects </A>
</UL>
<!--End of Table of Child-Links-->
<p>
<div class=navigation><hr><table align=center width="100%" cellpadding=0 cellspacing=2>
<tr>
<td><A HREF="ConfigParser-objects.html"><img width=32 height=32 align=bottom border=0 alt="next"
 src="../icons/next.gif"></A></td>
<td><A HREF="misc.html"><img width=32 height=32 align=bottom border=0 alt="up"
 src="../icons/up.gif"></A></td>
<td><A HREF="module-array.html"><img width=32 height=32 align=bottom border=0 alt="previous"
 src="../icons/previous.gif"></A></td>
<td align=center bgcolor="#99CCFF" width="100%">
 <b class=title>Python Library Reference</b></td>
<td><A HREF="contents.html"><img width=32 height=32 align=bottom border=0 alt="contents"
 src="../icons/contents.gif"></A></td>
<td><a
 href="modindex.html"><img width=32 height=32 align=bottom border=0 alt="modules"
 src="../icons/modules.gif"></a></td>
<td><A HREF="genindex.html"><img width=32 height=32 align=bottom border=0 alt="index"
 src="../icons/index.gif"></A></td>
</tr></table><b class=navlabel>Next:</b> <span class=sectref><A HREF="ConfigParser-objects.html">5.7.1 ConfigParser Objects</A></span>
<b class=navlabel>Up:</b> <span class=sectref><A HREF="misc.html">5. Miscellaneous Services</A></span>
<b class=navlabel>Previous:</b> <span class=sectref><A HREF="module-array.html">5.6 array  </A></span>
</div>
<!--End of Navigation Panel-->
<ADDRESS>
<hr>Send comments on this document to <a href="mailto:python-docs@python.org">python-docs@python.org</a>.
</ADDRESS>
</BODY>
</HTML>
