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')])
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 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.
A convenience method which coerces the option in the specified
section to a Boolean value. Note that the accepted values
for the option are 1, yes, true, and on,
which cause this method to return true, and 0, no,
false, and off, which cause it to return false. These
values are checked in a case-insensitive manner. Any other value will
cause it to raise ValueError.
Write a representation of the configuration to the specified file
object. This representation can be parsed by a future read()
call.
New in version 1.6.
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 version 1.6.
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.