diff options
author | Łukasz Langa <lukasz@langa.pl> | 2011-01-28 11:57:30 (GMT) |
---|---|---|
committer | Łukasz Langa <lukasz@langa.pl> | 2011-01-28 11:57:30 (GMT) |
commit | 66c908e6bffd5578b27cdecd398b5cd7e9874f90 (patch) | |
tree | afe17f4d0b8b259fc2f5c642da2de44ce2d61caf /Doc/library/configparser.rst | |
parent | 469271d4ea02322f526414c0ed51556410b0d3e6 (diff) | |
download | cpython-66c908e6bffd5578b27cdecd398b5cd7e9874f90.zip cpython-66c908e6bffd5578b27cdecd398b5cd7e9874f90.tar.gz cpython-66c908e6bffd5578b27cdecd398b5cd7e9874f90.tar.bz2 |
#11027: documented how to override SECTCRE
Diffstat (limited to 'Doc/library/configparser.rst')
-rw-r--r-- | Doc/library/configparser.rst | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/Doc/library/configparser.rst b/Doc/library/configparser.rst index d0d159b..cb6f259 100644 --- a/Doc/library/configparser.rst +++ b/Doc/library/configparser.rst @@ -716,6 +716,38 @@ may be overriden by subclasses or by attribute assignment. >>> list(custom['Section2'].keys()) ['AnotherKey'] +.. attribute:: SECTCRE + + A compiled regular expression used to parse section headers. The default + matches ``[section]`` to the name ``"section"``. Whitespace is considered part + of the section name, thus ``[ larch ]`` will be read as a section of name + ``" larch "``. Override this attribute if that's unsuitable. For example: + + .. doctest:: + + >>> config = """ + ... [Section 1] + ... option = value + ... + ... [ Section 2 ] + ... another = val + ... """ + >>> typical = ConfigParser() + >>> typical.read_string(config) + >>> typical.sections() + ['Section 1', ' Section 2 '] + >>> custom = ConfigParser() + >>> custom.SECTCRE = re.compile(r"\[ *(?P<header>[^]]+?) *\]") + >>> custom.read_string(config) + >>> custom.sections() + ['Section 1', 'Section 2'] + + .. note:: + + While ConfigParser objects also use an ``OPTCRE`` attribute for recognizing + option lines, it's not recommended to override it because that would + interfere with constructor options *allow_no_value* and *delimiters*. + Legacy API Examples ------------------- |