Skip to content

Commit

Permalink
bpo-37779 : Add information about the overriding behavior of ConfigPa…
Browse files Browse the repository at this point in the history
…rser.read (GH-15177)

Co-Authored-By: Kyle Stanley <[email protected]>
Co-Authored-By: Paul Ganssle <[email protected]>
  • Loading branch information
3 people authored Sep 23, 2020
1 parent 97d15ae commit 48b0b1b
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Doc/library/configparser.rst
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,30 @@ involves the ``DEFAULT`` section which provides default values for all other
sections [1]_. Note also that keys in sections are
case-insensitive and stored in lowercase [1]_.

It is possible to read several configurations into a single
:class:`ConfigParser`, where the most recently added configuration has the
highest priority. Any conflicting keys are taken from the more recent
configuration while the previously existing keys are retained.

.. doctest::

>>> another_config = configparser.ConfigParser()
>>> another_config.read('example.ini')
['example.ini']
>>> another_config['topsecret.server.com']['Port']
'50022'
>>> another_config.read_string("[topsecret.server.com]\nPort=48484")
>>> another_config['topsecret.server.com']['Port']
'48484'
>>> another_config.read_dict({"topsecret.server.com": {"Port": 21212}})
>>> another_config['topsecret.server.com']['Port']
'21212'
>>> another_config['topsecret.server.com']['ForwardX11']
'no'

This behaviour is equivalent to a :meth:`ConfigParser.read` call with several
files passed to the *filenames* parameter.


Supported Datatypes
-------------------
Expand Down

0 comments on commit 48b0b1b

Please sign in to comment.