[New-bugs-announce] [issue11027] Allow spaces around section header in ConfigParser

Kunjesh Kaushik report at bugs.python.org
Thu Jan 27 15:37:05 CET 2011

New submission from Kunjesh Kaushik <kunjesh.kaushik at gmail.com>:

It is often desirable to be able to write a section with spaces around the header, as in "[ default ]" instead of "[default]" for the sake of readability of configuration file. I am not sure if this is the "standard" format of configuration files.

The following (attached) patch will achieve the desired result. It is also backward-compatible. Kindly arrange for the patch to be applied to the repository or to a future release.

Original Code Location: http://svn.python.org/view/*checkout*/python/branches/release27-maint/Lib/ConfigParser.py?revision=84443

Index: Lib/ConfigParser.py
--- Lib/ConfigParser.py	(revision 84443)
+++ Lib/ConfigParser.py	(working copy)
@@ -432,7 +432,7 @@
     SECTCRE = re.compile(
         r'\['                                 # [
-        r'(?P<header>[^]]+)'                  # very permissive!
+        r'\s*(?P<header>[^]]+)\s*'            # very permissive!
         r'\]'                                 # ]
     OPTCRE = re.compile(

components: Library (Lib)
files: allow_spaces_around_section_header.diff
keywords: patch
messages: 127193
nosy: Kunjesh.Kaushik
priority: normal
severity: normal
status: open
title: Allow spaces around section header in ConfigParser
type: feature request
versions: Python 2.7
Added file: http://bugs.python.org/file20547/allow_spaces_around_section_header.diff

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list