be used for this purpose.
+.. testsetup::
+
+ import configparser
+
+
Quick Start
-----------
.. doctest::
- >>> import configparser
>>> config = configparser.ConfigParser()
>>> config.sections()
[]
'no'
>>> topsecret['Port']
'50022'
- >>> for key in config['bitbucket.org']: print(key)
- ...
+ >>> for key in config['bitbucket.org']: # doctest: +SKIP
+ ... print(key)
user
compressionlevel
serveraliveinterval
... 'bar': 'y',
... 'baz': 'z'}
... })
- >>> parser.sections()
+ >>> parser.sections() # doctest: +SKIP
['section3', 'section2', 'section1']
- >>> [option for option in parser['section3']]
+ >>> [option for option in parser['section3']] # doctest: +SKIP
['baz', 'foo', 'bar']
In these operations you need to use an ordered dictionary as well:
... ),
... ))
... )
- >>> parser.sections()
+ >>> parser.sections() # doctest: +SKIP
['s1', 's2']
- >>> [option for option in parser['s1']]
+ >>> [option for option in parser['s1']] # doctest: +SKIP
['1', '3', '5']
- >>> [option for option in parser['s2'].values()]
+ >>> [option for option in parser['s2'].values()] # doctest: +SKIP
['b', 'd', 'f']
* *allow_no_value*, default value: ``False``
... line #3
... """)
>>> print(parser['hashes']['shebang'])
-
+ <BLANKLINE>
#!/usr/bin/env python
# -*- coding: utf-8 -*-
>>> print(parser['hashes']['extensions'])
-
+ <BLANKLINE>
enabled_extension
another_extension
yet_another_extension
.. doctest::
+ >>> import re
>>> config = """
... [Section 1]
... option = value
... [ Section 2 ]
... another = val
... """
- >>> typical = ConfigParser()
+ >>> typical = configparser.ConfigParser()
>>> typical.read_string(config)
>>> typical.sections()
['Section 1', ' Section 2 ']
- >>> custom = ConfigParser()
+ >>> custom = configparser.ConfigParser()
>>> custom.SECTCRE = re.compile(r"\[ *(?P<header>[^]]+?) *\]")
>>> custom.read_string(config)
>>> custom.sections()
shared library can be accessed as attributes or by index. Please note that
accessing the function through an attribute caches the result and therefore
accessing it repeatedly returns the same object each time. On the other hand,
-accessing it through an index returns a new object each time:
+accessing it through an index returns a new object each time::
+ >>> from ctypes import CDLL
+ >>> libc = CDLL("libc.so.6") # On Linux
>>> libc.time == libc.time
True
>>> libc['time'] == libc['time']