diff --git a/Doc/library/configparser.rst b/Doc/library/configparser.rst index a7f75fd6e84f4c..5e61dfbbf70c64 100644 --- a/Doc/library/configparser.rst +++ b/Doc/library/configparser.rst @@ -1043,6 +1043,27 @@ ConfigParser Objects config.read(['site.cfg', os.path.expanduser('~/.myapp.cfg')], encoding='cp1250') + 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.example']['Port'] + '50022' + >>> another_config.read_string("[topsecret.server.example]\nPort=48484") + >>> another_config['topsecret.server.example']['Port'] + '48484' + >>> another_config.read_dict({"topsecret.server.example": {"Port": 21212}}) + >>> another_config['topsecret.server.example']['Port'] + '21212' + >>> another_config['topsecret.server.example']['ForwardX11'] + 'no' + .. versionadded:: 3.2 The *encoding* parameter. Previously, all files were read using the default encoding for :func:`open`.