Movatterモバイル変換


[0]ホーム

URL:


Up one LevelPython Library ReferenceContentsModule IndexIndex


9.2.1 RawConfigParser Objects

RawConfigParser 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,returnTrue; otherwise returnFalse.New in version 1.6.

read(filenames)
Attempt to read and parse a list of filenames, returning a list of filenameswhich were successfully parsed. 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')])
Changed in version 2.4:Returns list of successfully parsed filenames.

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)
Get anoption value for the namedsection.

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 are"1","yes","true", and"on",which cause this method to returnTrue, and"0","no","false", and"off", which cause it to returnFalse. Thesestring values are checked in a case-insensitive manner. Any other value willcause it to raiseValueError.

items(section)
Return a list of(name,value) pairs for eachoption in the givensection.

set(section, option, value)
If the given section exists, set the given option to the specifiedvalue; otherwise raiseNoSectionError. While it ispossible to useRawConfigParser (orConfigParser withraw parameters set to true) forinternal storage ofnon-string values, full functionality (including interpolation andoutput to files) can only be achieved using string values.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, returnTrue;otherwise returnFalse.New in version 1.6.

remove_section(section)
Remove the specifiedsection from the configuration.If the section in fact existed, returnTrue.Otherwise returnFalse.

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.


Up one LevelPython Library ReferenceContentsModule IndexIndex

Release 2.5.2, documentation updated on 21st February, 2008.
SeeAbout this document... for information on suggesting changes.
[8]ページ先頭

©2009-2025 Movatter.jp