summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorsblondon <sblondon@users.noreply.github.com>2020-09-23 12:28:58 (GMT)
committerGitHub <noreply@github.com>2020-09-23 12:28:58 (GMT)
commit48b0b1b121f26f811265f9eb06f195a3df38ef4b (patch)
tree2a4a0de7ea386e49203bbb430c6e9d47e7f4177f /Doc
parent97d15ae1d8411b49b1fcdc0c67c51849dccce9c9 (diff)
downloadcpython-48b0b1b121f26f811265f9eb06f195a3df38ef4b.zip
cpython-48b0b1b121f26f811265f9eb06f195a3df38ef4b.tar.gz
cpython-48b0b1b121f26f811265f9eb06f195a3df38ef4b.tar.bz2
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>
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/configparser.rst24
1 files changed, 24 insertions, 0 deletions
diff --git a/Doc/library/configparser.rst b/Doc/library/configparser.rst
index 2e22a54..646e8a3 100644
--- a/Doc/library/configparser.rst
+++ b/Doc/library/configparser.rst
@@ -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
-------------------