Skip to content

Commit 02ee819

Browse files
jugmac00blurb-it[bot]Laura Gutierrez Funderburk
authored
bpo-41963: document that ConfigParser strips off comments (GH-26197)
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Laura Gutierrez Funderburk <[email protected]>
1 parent 115dea9 commit 02ee819

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

Doc/library/configparser.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,6 +1153,13 @@ ConfigParser Objects
11531153
*space_around_delimiters* is true, delimiters between
11541154
keys and values are surrounded by spaces.
11551155

1156+
.. note::
1157+
1158+
Comments in the original configuration file are not preserved when
1159+
writing the configuration back.
1160+
What is considered a comment, depends on the given values for
1161+
*comment_prefix* and *inline_comment_prefix*.
1162+
11561163

11571164
.. method:: remove_option(section, option)
11581165

Lib/configparser.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,9 @@ def write(self, fp, space_around_delimiters=True):
908908
909909
If `space_around_delimiters' is True (the default), delimiters
910910
between keys and values are surrounded by spaces.
911+
912+
Please note that comments in the original configuration file are not
913+
preserved when writing the configuration back.
911914
"""
912915
if space_around_delimiters:
913916
d = " {} ".format(self._delimiters[0])
@@ -1006,7 +1009,7 @@ def _read(self, fp, fpname):
10061009
Configuration files may include comments, prefixed by specific
10071010
characters (`#' and `;' by default). Comments may appear on their own
10081011
in an otherwise empty line or may be entered in lines holding values or
1009-
section names.
1012+
section names. Please note that comments get stripped off when reading configuration files.
10101013
"""
10111014
elements_added = set()
10121015
cursect = None # None, or a dictionary
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Document that ``ConfigParser`` strips off comments when reading configuration files.

0 commit comments

Comments
 (0)