On this page
configparser.SectionProxy
Prev: configparser.RawConfigParser | Up: configparser | Next: configparser.UnnamedSectionDisabledError
Rel: configparser.BasicInterpolation, configparser.ConfigParser, configparser.ConverterMapping, configparser.DuplicateOptionError
Ref: docs.python.org — configparser.SectionProxy
Tags: #public #python3 #stdlib #configparser
Import
import configparser
from configparser import SectionProxy
Signature & Overview
configparser.SectionProxy(parser, name)
A proxy for a single section from a parser.
Methods & Attributes
SectionProxy.clear(self)— D.clear() -> None. Remove all items from D.SectionProxy.get(self, option, fallback=None, *, raw=False, vars=None, _impl=None, **kwargs)— Get an option value.SectionProxy.items(self)— D.items() -> a set-like object providing a view on D's itemsSectionProxy.keys(self)— D.keys() -> a set-like object providing a view on D's keysSectionProxy.name(...)—SectionProxy.namemethod/property.SectionProxy.parser(...)—SectionProxy.parsermethod/property.SectionProxy.pop(self, key, default=<object object at 0x1040b41c0>)— value. If key is not found, d is returned if given, otherwise KeyError is raised.SectionProxy.popitem(self)— as a 2-tuple; but raise KeyError if D is empty.SectionProxy.setdefault(self, key, default=None)— D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in DSectionProxy.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:SectionProxy.values(self)— D.values() -> an object providing a view on D's values
Usage
import configparser
cp = configparser.ConfigParser()
cp.read_string("[db]\nport = 5432\n")
sec = cp["db"]
assert isinstance(sec, configparser.SectionProxy) and sec.getint("port") == 5432
Gotchas
- Live view backed by
ConfigParser: Mutatingsec["port"] = "5433"updatescpimmediately.
REPL Inspect
from configparser import SectionProxy
help(SectionProxy)
Linked from
Related notes
- tuts/python3/stdlib_module/configparser/RawConfigParser Linked here; links to this page; shared tags: #configparser, #stdlib
- tuts/python3/stdlib_module/configparser/UnnamedSectionDisabledError Linked here; links to this page; shared tags: #configparser, #stdlib
- tuts/python3/stdlib_module/configparser/BasicInterpolation Linked here; shared tags: #configparser, #stdlib
- tuts/python3/stdlib_module/configparser/ConfigParser Linked here; shared tags: #configparser, #stdlib
- tuts/python3/stdlib_module/configparser/ConverterMapping Linked here; shared tags: #configparser, #stdlib
- tuts/python3/stdlib_module/configparser/DuplicateOptionError Linked here; shared tags: #configparser, #stdlib
- tuts/python3/stdlib_module/configparser links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/configparser/DuplicateSectionError shared tags: #configparser, #stdlib
- tuts/python3/stdlib_module/configparser/ExtendedInterpolation shared tags: #configparser, #stdlib
- tuts/python3/stdlib_module/configparser/Interpolation shared tags: #configparser, #stdlib