Back to index

python3.2  3.2.2
Classes | Variables
configparser Namespace Reference

Classes

class  Error
class  NoSectionError
class  DuplicateSectionError
class  DuplicateOptionError
class  NoOptionError
class  InterpolationError
class  InterpolationMissingOptionError
class  InterpolationSyntaxError
class  InterpolationDepthError
class  ParsingError
class  MissingSectionHeaderError
class  Interpolation
class  BasicInterpolation
class  ExtendedInterpolation
class  LegacyInterpolation
class  RawConfigParser
class  ConfigParser
class  SafeConfigParser
class  SectionProxy

Variables

list __all__
string DEFAULTSECT = "DEFAULT"
int MAX_INTERPOLATION_DEPTH = 10
tuple _UNSET = object()

Detailed Description

Configuration file parser.

A configuration file consists of sections, lead by a "[section]" header,
and followed by "name: value" entries, with continuations and such in
the style of RFC 822.

Intrinsic defaults can be specified by passing them into the
ConfigParser constructor as a dictionary.

class:

ConfigParser -- responsible for parsing a list of
                configuration files, and managing the parsed database.

methods:

__init__(defaults=None, dict_type=_default_dict, allow_no_value=False,
         delimiters=('=', ':'), comment_prefixes=('#', ';'),
         inline_comment_prefixes=None, strict=True,
         empty_lines_in_values=True):
    Create the parser. When `defaults' is given, it is initialized into the
    dictionary or intrinsic defaults. The keys must be strings, the values
    must be appropriate for %()s string interpolation.

    When `dict_type' is given, it will be used to create the dictionary
    objects for the list of sections, for the options within a section, and
    for the default values.

    When `delimiters' is given, it will be used as the set of substrings
    that divide keys from values.

    When `comment_prefixes' is given, it will be used as the set of
    substrings that prefix comments in empty lines. Comments can be
    indented.

    When `inline_comment_prefixes' is given, it will be used as the set of
    substrings that prefix comments in non-empty lines.

    When `strict` is True, the parser won't allow for any section or option
    duplicates while reading from a single source (file, string or
    dictionary). Default is True.

    When `empty_lines_in_values' is False (default: True), each empty line
    marks the end of an option. Otherwise, internal empty lines of
    a multiline option are kept as part of the value.

    When `allow_no_value' is True (default: False), options without
    values are accepted; the value presented for these is None.

sections()
    Return all the configuration section names, sans DEFAULT.

has_section(section)
    Return whether the given section exists.

has_option(section, option)
    Return whether the given option exists in the given section.

options(section)
    Return list of configuration options for the named section.

read(filenames, encoding=None)
    Read and parse the list of named configuration files, given by
    name.  A single filename is also allowed.  Non-existing files
    are ignored.  Return list of successfully read files.

read_file(f, filename=None)
    Read and parse one configuration file, given as a file object.
    The filename defaults to f.name; it is only used in error
    messages (if f has no `name' attribute, the string `<???>' is used).

read_string(string)
    Read configuration from a given string.

read_dict(dictionary)
    Read configuration from a dictionary. Keys are section names,
    values are dictionaries with keys and values that should be present
    in the section. If the used dictionary type preserves order, sections
    and their keys will be added in order. Values are automatically
    converted to strings.

get(section, option, raw=False, vars=None, fallback=_UNSET)
    Return a string value for the named option.  All % interpolations are
    expanded in the return values, based on the defaults passed into the
    constructor and the DEFAULT section.  Additional substitutions may be
    provided using the `vars' argument, which must be a dictionary whose
    contents override any pre-existing defaults. If `option' is a key in
    `vars', the value from `vars' is used.

getint(section, options, raw=False, vars=None, fallback=_UNSET)
    Like get(), but convert value to an integer.

getfloat(section, options, raw=False, vars=None, fallback=_UNSET)
    Like get(), but convert value to a float.

getboolean(section, options, raw=False, vars=None, fallback=_UNSET)
    Like get(), but convert value to a boolean (currently case
    insensitively defined as 0, false, no, off for False, and 1, true,
    yes, on for True).  Returns False or True.

items(section=_UNSET, raw=False, vars=None)
    If section is given, return a list of tuples with (section_name,
    section_proxy) for each section, including DEFAULTSECT. Otherwise,
    return a list of tuples with (name, value) for each option
    in the section.

remove_section(section)
    Remove the given file section and all its options.

remove_option(section, option)
    Remove the given option from the given section.

set(section, option, value)
    Set the given option.

write(fp, space_around_delimiters=True)
    Write the configuration state in .ini format. If
    `space_around_delimiters' is True (the default), delimiters
    between keys and values are surrounded by spaces.

Variable Documentation

Initial value:
00001 ["NoSectionError", "DuplicateOptionError", "DuplicateSectionError",
00002            "NoOptionError", "InterpolationError", "InterpolationDepthError",
00003            "InterpolationSyntaxError", "ParsingError",
00004            "MissingSectionHeaderError",
00005            "ConfigParser", "SafeConfigParser", "RawConfigParser",
00006            "DEFAULTSECT", "MAX_INTERPOLATION_DEPTH"]

Definition at line 130 of file configparser.py.

Definition at line 353 of file configparser.py.

Definition at line 137 of file configparser.py.

Definition at line 139 of file configparser.py.