Info Node: (python2.1-lib.info)ConfigParser Objects
(python2.1-lib.info)ConfigParser Objects
ConfigParser Objects
--------------------
`ConfigParser' instances have the following methods:
`defaults()'
Return a dictionary containing the instance-wide defaults.
`sections()'
Return a list of the sections available; `DEFAULT' is not included
in the list.
`add_section(section)'
Add a section named SECTION to the instance. If a section by the
given name already exists, `DuplicateSectionError' is raised.
`has_section(section)'
Indicates whether the named section is present in the
configuration. The `DEFAULT' section is not acknowledged.
`options(section)'
Returns a list of options available in the specified SECTION.
`has_option(section, option)'
If the given section exists, and contains the given option. return
1; otherwise return 0. (New in 1.6)
`read(filenames)'
Read and parse a list of filenames. If FILENAMES is a string or
Unicode string, it is treated as a single filename. If a file
named in FILENAMES cannot be opened, that file will be ignored.
This is designed so that you can specify a list of potential
configuration file locations (for example, the current directory,
the user's home directory, and some system-wide directory), and all
existing configuration files in the list will be read. If none of
the named files exist, the `ConfigParser' instance will contain an
empty dataset. An application which requires initial values to be
loaded from a file should load the required file or files using
`readfp()' before calling `read()' for any optional files:
import ConfigParser, os
config = ConfigParser.ConfigParser()
config.readfp(open('defaults.cfg'))
config.read(['site.cfg', os.path.expanduser('~/.myapp.cfg')])
`readfp(fp[, filename])'
Read and parse configuration data from the file or file-like
object in FP (only the `readline()' method is used). If FILENAME
is omitted and FP has a `name' attribute, that is used for
FILENAME; the default is `<???>'.
`get(section, option[, raw[, vars]])'
Get an OPTION value for the provided 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.
`getint(section, option)'
A convenience method which coerces the OPTION in the specified
SECTION to an integer.
`getfloat(section, option)'
A convenience method which coerces the OPTION in the specified
SECTION to a floating point number.
`getboolean(section, option)'
A convenience method which coerces the OPTION in the specified
SECTION to a boolean value. Note that the only accepted values
for the option are `0' and `1', any others will raise `ValueError'.
`set(section, option, value)'
If the given section exists, set the given option to the specified
value; otherwise raise `NoSectionError'. (New in 1.6)
`write(fileobject)'
Write a representation of the configuration to the specified file
object. This representation can be parsed by a future `read()'
call. (New in 1.6)
`remove_option(section, option)'
Remove the specified OPTION from the specified SECTION. If the
section does not exist, raise `NoSectionError'. If the option
existed to be removed, return 1; otherwise return 0. (New in 1.6)
`remove_section(section)'
Remove the specified SECTION from the configuration. If the
section in fact existed, return 1. Otherwise return 0.
`optionxform(option)'
Transforms the option name OPTION as found in an input file or as
passed in by client code to the form that should be used in the
internal structures. The default implementation returns a
lower-case version of OPTION; subclasses may override this or
client code can set an attribute of this name on instances to
affect this behavior. Setting this to `str()', for example, would
make option names case sensitive.
automatically generated byinfo2wwwversion 1.2.2.9