Movatterモバイル変換


[0]ホーム

URL:


Previous PageUp One LevelNext PagePython Library ReferenceContentsModule IndexIndex
Previous:5.10 ConfigParserUp:5.10 ConfigParserNext:5.11 fileinput

 
5.10.1 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 notincluded in the list.

add_section(section)
Add a section namedsection to the instance. If a section bythe given name already exists,DuplicateSectionError israised.

has_section(section)
Indicates whether the named section is present in theconfiguration. TheDEFAULT section is not acknowledged.

options(section)
Returns a list of options available in the specifiedsection.

has_option(section, option)
If the given section exists, and contains the given option. return 1;otherwise return 0.New in version 1.6.

read(filenames)
Read and parse a list of filenames. Iffilenames is a string orUnicode string, it is treated as a single filename.If a file named infilenames cannot be opened, that file will beignored. This is designed so that you can specify a list of potentialconfiguration file locations (for example, the current directory, theuser's home directory, and some system-wide directory), and allexisting configuration files in the list will be read. If none of thenamed files exist, theConfigParser instance will contain anempty dataset. An application which requires initial values to beloaded from a file should load the required file or files usingreadfp() before callingread() for any optionalfiles:

import ConfigParser, osconfig = 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 infp (only thereadline() method is used). Iffilename is omitted andfp has aname attribute,that is used forfilename; the default is "<???>".

get(section, option[, raw[, vars]])
Get anoption value for the providedsection. All the"%" interpolations are expanded in the return values, based onthe defaults passed into the constructor, as well as the optionsvars provided, unless theraw argument is true.

getint(section, option)
A convenience method which coerces theoption in the specifiedsection to an integer.

getfloat(section, option)
A convenience method which coerces theoption in the specifiedsection to a floating point number.

getboolean(section, option)
A convenience method which coerces theoption in the specifiedsection to a Boolean value. Note that the accepted valuesfor the option are1,yes,true, andon,which cause this method to return true, and0,no,false, andoff, which cause it to return false. Thesevalues are checked in a case-insensitive manner. Any other value willcause it to raiseValueError.

set(section, option, value)
If the given section exists, set the given option to the specified value;otherwise raiseNoSectionError.New in version 1.6.

write(fileobject)
Write a representation of the configuration to the specified fileobject. This representation can be parsed by a futureread()call.New in version 1.6.

remove_option(section, option)
Remove the specifiedoption from the specifiedsection.If the section does not exist, raiseNoSectionError. If the option existed to be removed, return 1; otherwise return 0.New in version 1.6.

remove_section(section)
Remove the specifiedsection from the configuration.If the section in fact existed, return 1. Otherwise return 0.

optionxform(option)
Transforms the option nameoption as found in an input file oras passed in by client code to the form that should be used in theinternal structures. The default implementation returns a lower-caseversion ofoption; subclasses may override this or client codecan set an attribute of this name on instances to affect thisbehavior. Setting this tostr(), for example, would makeoption names case sensitive.


Previous PageUp One LevelNext PagePython Library ReferenceContentsModule IndexIndex
Previous:5.10 ConfigParserUp:5.10 ConfigParserNext:5.11 fileinput
Release 2.2.3, documentation updated on 30 May 2003.
SeeAbout this document... for information on suggesting changes.
[8]ページ先頭

©2009-2026 Movatter.jp