Skip to content

Commit 48b0b1b

Browse files
sblondonaerospganssle
authored
bpo-37779 : Add information about the overriding behavior of ConfigParser.read (GH-15177)
Co-Authored-By: Kyle Stanley <aeros167@gmail.com> Co-Authored-By: Paul Ganssle <p.ganssle@gmail.com>
1 parent 97d15ae commit 48b0b1b

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Doc/library/configparser.rst

+24
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,30 @@ involves the ``DEFAULT`` section which provides default values for all other
135135
sections [1]_. Note also that keys in sections are
136136
case-insensitive and stored in lowercase [1]_.
137137

138+
It is possible to read several configurations into a single
139+
:class:`ConfigParser`, where the most recently added configuration has the
140+
highest priority. Any conflicting keys are taken from the more recent
141+
configuration while the previously existing keys are retained.
142+
143+
.. doctest::
144+
145+
>>> another_config = configparser.ConfigParser()
146+
>>> another_config.read('example.ini')
147+
['example.ini']
148+
>>> another_config['topsecret.server.com']['Port']
149+
'50022'
150+
>>> another_config.read_string("[topsecret.server.com]\nPort=48484")
151+
>>> another_config['topsecret.server.com']['Port']
152+
'48484'
153+
>>> another_config.read_dict({"topsecret.server.com": {"Port": 21212}})
154+
>>> another_config['topsecret.server.com']['Port']
155+
'21212'
156+
>>> another_config['topsecret.server.com']['ForwardX11']
157+
'no'
158+
159+
This behaviour is equivalent to a :meth:`ConfigParser.read` call with several
160+
files passed to the *filenames* parameter.
161+
138162

139163
Supported Datatypes
140164
-------------------

0 commit comments

Comments
 (0)