summaryrefslogtreecommitdiff
path: root/Doc/library/configparser.rst
diff options
context:
space:
mode:
Diffstat (limited to 'Doc/library/configparser.rst')
-rw-r--r--Doc/library/configparser.rst50
1 files changed, 9 insertions, 41 deletions
diff --git a/Doc/library/configparser.rst b/Doc/library/configparser.rst
index f51c580c0d..5a2178f11b 100644
--- a/Doc/library/configparser.rst
+++ b/Doc/library/configparser.rst
@@ -445,20 +445,19 @@ the :meth:`__init__` options:
Hint: if you want to specify default values for a specific section, use
:meth:`read_dict` before you read the actual file.
-* *dict_type*, default value: :class:`collections.OrderedDict`
+* *dict_type*, default value: :class:`dict`
This option has a major impact on how the mapping protocol will behave and how
- the written configuration files look. With the default ordered
- dictionary, every section is stored in the order they were added to the
- parser. Same goes for options within sections.
+ the written configuration files look. With the standard dictionary, every
+ section is stored in the order they were added to the parser. Same goes for
+ options within sections.
An alternative dictionary type can be used for example to sort sections and
- options on write-back. You can also use a regular dictionary for performance
- reasons.
+ options on write-back.
Please note: there are ways to add a set of key-value pairs in a single
operation. When you use a regular dictionary in those operations, the order
- of the keys may be random. For example:
+ of the keys will be ordered. For example:
.. doctest::
@@ -474,40 +473,9 @@ the :meth:`__init__` options:
... 'baz': 'z'}
... })
>>> parser.sections() # doctest: +SKIP
- ['section3', 'section2', 'section1']
- >>> [option for option in parser['section3']] # doctest: +SKIP
- ['baz', 'foo', 'bar']
-
- In these operations you need to use an ordered dictionary as well:
-
- .. doctest::
-
- >>> from collections import OrderedDict
- >>> parser = configparser.ConfigParser()
- >>> parser.read_dict(
- ... OrderedDict((
- ... ('s1',
- ... OrderedDict((
- ... ('1', '2'),
- ... ('3', '4'),
- ... ('5', '6'),
- ... ))
- ... ),
- ... ('s2',
- ... OrderedDict((
- ... ('a', 'b'),
- ... ('c', 'd'),
- ... ('e', 'f'),
- ... ))
- ... ),
- ... ))
- ... )
- >>> parser.sections() # doctest: +SKIP
- ['s1', 's2']
- >>> [option for option in parser['s1']] # doctest: +SKIP
- ['1', '3', '5']
- >>> [option for option in parser['s2'].values()] # doctest: +SKIP
- ['b', 'd', 'f']
+ ['section1', 'section2', 'section3']
+ >>> [option for option in parser['section3']] # doctest: +SKIP
+ ['foo', 'bar', 'baz']
* *allow_no_value*, default value: ``False``