Movatterモバイル変換
[0]ホーム
This module defines the classConfigParser. TheConfigParser class implements a basic configuration fileparser language which provides a structure similar to what you wouldfind on Microsoft Windows INI files. You can use this to write Pythonprograms which can be customized by end users easily.
The configuration file consists of sections, lead by a"[section]" header and followed by "name: value" entries,with continuations in the style ofRFC 822; "name=value" isalso accepted. Note that leading whitespace is removed from values.The optional values can contain format strings which refer to othervalues in the same section, or values in a specialDEFAULT section. Additional defaults can be provided uponinitialization and retrieval. Lines beginning with "#" or";" are ignored and may be used to provide comments.
For example:
foodir: %(dir)s/whateverdir=frob
would resolve the "%(dir)s" to the value of"dir" ("frob" in this case). All reference expansions aredone on demand.
Default values can be specified by passing them into theConfigParser constructor as a dictionary. Additional defaults may be passed into theget() method which will override allothers.
- classConfigParser([defaults])
- Return a new instance of theConfigParser class. Whendefaults is given, it is initialized into the dictionary ofintrinsic defaults. The keys must be strings, and the values must be appropriate for the "%()s" string interpolation. Note that__name__ is an intrinsic default; its value is the section name,and will override any value provided indefaults.
- exceptionNoSectionError
- Exception raised when a specified section is not found.
- exceptionDuplicateSectionError
- Exception raised when multiple sections with the same name are found,or ifadd_section() is called with the name of a section that is already present.
- exceptionNoOptionError
- Exception raised when a specified option is not found in the specified section.
- exceptionInterpolationError
- Exception raised when problems occur performing string interpolation.
- exceptionInterpolationDepthError
- Exception raised when string interpolation cannot be completed becausethe number of iterations exceedsMAX_INTERPOLATION_DEPTH.
- exceptionMissingSectionHeaderError
- Exception raised when attempting to parse a file which has no sectionheaders.
- exceptionParsingError
- Exception raised when errors occur attempting to parse a file.
- MAX_INTERPOLATION_DEPTH
- The maximum depth for recursive interpolation forget() whentheraw parameter is false. Setting this does not change theallowed recursion depth.
See Also:
- Moduleshlex:
- Support for a creating Unix shell-like minilanguages which can be used as an alternate format for application configuration files.
SubsectionsSeeAbout this document... for information on suggesting changes.
[8]ページ先頭