From dc8f924539e83f57c64401508b3dbf206ac3d59f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joon=20Hwan=20=EA=B9=80=EC=A4=80=ED=99=98?= Date: Sun, 6 Aug 2023 15:20:25 +0900 Subject: [PATCH 1/2] Add docs Order of configparser.ConfigParser.read() arguments --- Doc/library/configparser.rst | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Doc/library/configparser.rst b/Doc/library/configparser.rst index a7f75fd6e84f4c..aefe990c3eb55e 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`. From 8cd37cee3268d150d7016cba2e71caf690339c88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joon=20Hwan=20=EA=B9=80=EC=A4=80=ED=99=98?= Date: Sun, 6 Aug 2023 15:37:25 +0900 Subject: [PATCH 2/2] add indent --- Doc/library/configparser.rst | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/Doc/library/configparser.rst b/Doc/library/configparser.rst index aefe990c3eb55e..5e61dfbbf70c64 100644 --- a/Doc/library/configparser.rst +++ b/Doc/library/configparser.rst @@ -1048,21 +1048,21 @@ ConfigParser Objects 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' + .. 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