Skip to content
Next Next commit
Add information about the overriding behavior of ConfigParser.read me…
…thods
  • Loading branch information
sblondon committed Aug 8, 2019
commit 3ff9d2804079eb3ef4c3fbefec77d814265d9a1b
20 changes: 20 additions & 0 deletions Doc/library/configparser.rst
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,26 @@ sections [1]_. Note also that keys in sections are
case-insensitive and stored in lowercase [1]_.

Comment thread
sblondon marked this conversation as resolved.

If we need to read several configurations, each one having more priority than the previous one, we can use the same :class:`ConfigParser` instance to override previous defined data and keep not redefined data.
Comment thread
sblondon marked this conversation as resolved.
Outdated
Comment thread
sblondon marked this conversation as resolved.
Outdated

.. doctest::

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

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

Comment thread
sblondon marked this conversation as resolved.
Supported Datatypes
-------------------

Expand Down