On this page
configparser.ConverterMapping
Prev: configparser.ConfigParser | Up: configparser | Next: configparser.DuplicateOptionError
Rel: configparser.BasicInterpolation, configparser.ConfigParser, configparser.DuplicateOptionError, configparser.DuplicateSectionError
Ref: docs.python.org — configparser.ConverterMapping
Tags: #public #python3 #stdlib #configparser
Import
import configparser
from configparser import ConverterMapping
Signature & Overview
configparser.ConverterMapping(parser)
Enables reuse of get*() methods between the parser and section proxies.
Methods & Attributes
ConverterMapping.clear(self)— D.clear() -> None. Remove all items from D.ConverterMapping.get(self, key, default=None)— D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.ConverterMapping.items(self)— D.items() -> a set-like object providing a view on D's itemsConverterMapping.keys(self)— D.keys() -> a set-like object providing a view on D's keysConverterMapping.pop(self, key, default=<object object at 0x1040b41c0>)— value. If key is not found, d is returned if given, otherwise KeyError is raised.ConverterMapping.popitem(self)— as a 2-tuple; but raise KeyError if D is empty.ConverterMapping.setdefault(self, key, default=None)— D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in DConverterMapping.update(self, other=(), /, **kwds)— If E present and has a .keys() method, does: for k in E.keys(): D[k] = E[k] If E present and lacks .keys() method, does:ConverterMapping.values(self)— D.values() -> an object providing a view on D's values
Usage
import configparser
cp = configparser.ConfigParser(converters={"list": lambda s: [x.strip() for x in s.split(",")]})
cp.read_string("[app]\ntags = a, b, c\n")
assert isinstance(cp.converters, configparser.ConverterMapping)
assert cp["app"].getlist("tags") == ["a", "b", "c"]
Gotchas
- Registers custom
get<name>()methods automatically on both the parser and everySectionProxy.
REPL Inspect
from configparser import ConverterMapping
help(ConverterMapping)
Linked from
- tuts/python3/stdlib_module/configparser
- tuts/python3/stdlib_module/configparser/BasicInterpolation
- tuts/python3/stdlib_module/configparser/ConfigParser
- tuts/python3/stdlib_module/configparser/DuplicateOptionError
- tuts/python3/stdlib_module/configparser/DuplicateSectionError
- tuts/python3/stdlib_module/configparser/ExtendedInterpolation
- tuts/python3/stdlib_module/configparser/Interpolation
- tuts/python3/stdlib_module/configparser/InterpolationDepthError
- tuts/python3/stdlib_module/configparser/InterpolationError
- tuts/python3/stdlib_module/configparser/InterpolationMissingOptionError
- tuts/python3/stdlib_module/configparser/InterpolationSyntaxError
- tuts/python3/stdlib_module/configparser/InvalidWriteError
- tuts/python3/stdlib_module/configparser/MissingSectionHeaderError
- tuts/python3/stdlib_module/configparser/MultilineContinuationError
- tuts/python3/stdlib_module/configparser/NoOptionError
- tuts/python3/stdlib_module/configparser/NoSectionError
- tuts/python3/stdlib_module/configparser/ParsingError
- tuts/python3/stdlib_module/configparser/RawConfigParser
- tuts/python3/stdlib_module/configparser/SectionProxy
- tuts/python3/stdlib_module/configparser/UnnamedSectionDisabledError
Related notes
- tuts/python3/stdlib_module/configparser/BasicInterpolation Linked here; links to this page; shared tags: #configparser, #stdlib
- tuts/python3/stdlib_module/configparser/ConfigParser Linked here; links to this page; shared tags: #configparser, #stdlib
- tuts/python3/stdlib_module/configparser/DuplicateOptionError Linked here; links to this page; shared tags: #configparser, #stdlib
- tuts/python3/stdlib_module/configparser/DuplicateSectionError Linked here; links to this page; shared tags: #configparser, #stdlib
- tuts/python3/stdlib_module/configparser/ExtendedInterpolation links to this page; shared tags: #configparser, #stdlib
- tuts/python3/stdlib_module/configparser/Interpolation links to this page; shared tags: #configparser, #stdlib
- tuts/python3/stdlib_module/configparser/InterpolationDepthError links to this page; shared tags: #configparser, #stdlib
- tuts/python3/stdlib_module/configparser/InterpolationError links to this page; shared tags: #configparser, #stdlib
- tuts/python3/stdlib_module/configparser/InterpolationMissingOptionError links to this page; shared tags: #configparser, #stdlib
- tuts/python3/stdlib_module/configparser/InterpolationSyntaxError links to this page; shared tags: #configparser, #stdlib