diff options
author | Georg Brandl <georg@python.org> | 2010-08-01 21:03:01 +0000 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2010-08-01 21:03:01 +0000 |
commit | 1fa11af7aa52e481caafe8cb56e68a1adbd3ced2 (patch) | |
tree | 8e57019e0b9d5f9d12c42758511f1196cac9e558 /Doc/library/configparser.rst | |
parent | 745e86b3f81463ab1a18e63374f27a522a0a784f (diff) | |
download | cpython-git-1fa11af7aa52e481caafe8cb56e68a1adbd3ced2.tar.gz |
Merged revisions 83226-83227,83229-83232 via svnmerge from
svn+ssh://svn.python.org/python/branches/py3k
........
r83226 | georg.brandl | 2010-07-29 16:17:12 +0200 (Do, 29 Jul 2010) | 1 line
#1090076: explain the behavior of *vars* in get() better.
........
r83227 | georg.brandl | 2010-07-29 16:23:06 +0200 (Do, 29 Jul 2010) | 1 line
Use Py_CLEAR().
........
r83229 | georg.brandl | 2010-07-29 16:32:22 +0200 (Do, 29 Jul 2010) | 1 line
#9407: document configparser.Error.
........
r83230 | georg.brandl | 2010-07-29 16:36:11 +0200 (Do, 29 Jul 2010) | 1 line
Use correct directive and name.
........
r83231 | georg.brandl | 2010-07-29 16:46:07 +0200 (Do, 29 Jul 2010) | 1 line
#9397: remove mention of dbm.bsd which does not exist anymore.
........
r83232 | georg.brandl | 2010-07-29 16:49:08 +0200 (Do, 29 Jul 2010) | 1 line
#9388: remove ERA_YEAR which is never defined in the source code.
........
Diffstat (limited to 'Doc/library/configparser.rst')
-rw-r--r-- | Doc/library/configparser.rst | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/Doc/library/configparser.rst b/Doc/library/configparser.rst index 1d097f942e..5ddfcd7502 100644 --- a/Doc/library/configparser.rst +++ b/Doc/library/configparser.rst @@ -35,6 +35,18 @@ section, or values in a special ``DEFAULT`` section. Additional defaults can be provided on initialization and retrieval. Lines beginning with ``'#'`` or ``';'`` are ignored and may be used to provide comments. +Configuration files may include comments, prefixed by specific characters (``#`` +and ``;``). Comments may appear on their own in an otherwise empty line, or may +be entered in lines holding values or spection names. In the latter case, they +need to be preceded by a whitespace character to be recognized as a comment. +(For backwards compatibility, only ``;`` starts an inline comment, while ``#`` +does not.) + +On top of the core functionality, :class:`SafeConfigParser` supports +interpolation. This means values can contain format strings which refer to +other values in the same section, or values in a special ``DEFAULT`` section. +Additional defaults can be provided on initialization. + For example:: [My Section] @@ -100,6 +112,11 @@ write-back, as will be the keys within each section. The default *dict_type* is :class:`collections.OrderedDict`. +.. exception:: Error + + Base class for all other configparser exceptions. + + .. exception:: NoSectionError Exception raised when a specified section is not found. @@ -331,10 +348,13 @@ The :class:`ConfigParser` class extends some methods of the .. method:: ConfigParser.get(section, option, raw=False, vars=None) - Get an *option* value for the named *section*. All the ``'%'`` interpolations - are expanded in the return values, based on the defaults passed into the - constructor, as well as the options *vars* provided, unless the *raw* argument - is true. + Get an *option* value for the named *section*. If *vars* is provided, it + must be a dictionary. The *option* is looked up in *vars* (if provided), + *section*, and in *defaults* in that order. + + All the ``'%'`` interpolations are expanded in the return values, unless the + *raw* argument is true. Values for interpolation keys are looked up in the + same manner as the option. .. method:: ConfigParser.items(section, raw=False, vars=None) |