--- configparser.rst 2016-12-03 20:32:38.062394107 +0100
+++ configparser2nd.rst 2016-12-03 20:31:57.442393448 +0100
@@ -68,6 +68,10 @@
:mod:`configparser` classes can read and write such files. Let's start by
creating the above configuration file programmatically.
+.. testsetup::
+
+ import configparser
+
.. doctest::
>>> import configparser
@@ -116,13 +120,13 @@
'no'
>>> topsecret['Port']
'50022'
- >>> for key in config['bitbucket.org']: print(key)
- ...
- user
- compressionlevel
- serveraliveinterval
+ >>> for key in sorted(config['bitbucket.org']):
+ ... print(key)
compression
+ compressionlevel
forwardx11
+ serveraliveinterval
+ user
>>> config['bitbucket.org']['ForwardX11']
'yes'
@@ -469,10 +473,10 @@
... 'bar': 'y',
... 'baz': 'z'}
... })
- >>> parser.sections()
- ['section3', 'section2', 'section1']
- >>> [option for option in parser['section3']]
- ['baz', 'foo', 'bar']
+ >>> sorted(parser.sections())
+ ['section1', 'section2', 'section3']
+ >>> [option for option in sorted(parser['section3'])]
+ ['bar', 'baz', 'foo']
In these operations you need to use an ordered dictionary as well:
@@ -514,8 +518,6 @@
.. doctest::
- >>> import configparser
-
>>> sample_config = """
... [mysqld]
... user = mysql
@@ -571,7 +573,9 @@
values with characters used as comment prefixes. When in doubt, avoid
setting *inline_comment_prefixes*. In any circumstances, the only way of
storing comment prefix characters at the beginning of a line in multiline
- values is to interpolate the prefix, for example::
+ values is to interpolate the prefix, for example:
+
+ .. doctest::
>>> from configparser import ConfigParser, ExtendedInterpolation
>>> parser = ConfigParser(interpolation=ExtendedInterpolation())
@@ -597,11 +601,11 @@
... line #3
... """)
>>> print(parser['hashes']['shebang'])
-
+