Make the doctests presentation-friendlier.
This commit is contained in:
parent
ade57d0485
commit
61854332b9
|
@ -6,6 +6,11 @@
|
||||||
.. sectionauthor:: Skip Montanaro <skip@automatrix.com>
|
.. sectionauthor:: Skip Montanaro <skip@automatrix.com>
|
||||||
|
|
||||||
|
|
||||||
|
.. testsetup::
|
||||||
|
|
||||||
|
import operator
|
||||||
|
from operator import itemgetter
|
||||||
|
|
||||||
|
|
||||||
The :mod:`operator` module exports a set of functions implemented in C
|
The :mod:`operator` module exports a set of functions implemented in C
|
||||||
corresponding to the intrinsic operators of Python. For example,
|
corresponding to the intrinsic operators of Python. For example,
|
||||||
|
@ -481,12 +486,10 @@ objects.
|
||||||
Example: Build a dictionary that maps the ordinals from ``0`` to ``255`` to
|
Example: Build a dictionary that maps the ordinals from ``0`` to ``255`` to
|
||||||
their character equivalents.
|
their character equivalents.
|
||||||
|
|
||||||
>>> import operator
|
|
||||||
>>> d = {}
|
>>> d = {}
|
||||||
>>> keys = range(256)
|
>>> keys = range(256)
|
||||||
>>> vals = map(chr, keys)
|
>>> vals = map(chr, keys)
|
||||||
>>> map(operator.setitem, [d]*len(keys), keys, vals)
|
>>> map(operator.setitem, [d]*len(keys), keys, vals) # doctest: +SKIP
|
||||||
[None, None, ..., None]
|
|
||||||
|
|
||||||
.. XXX: find a better, readable, example
|
.. XXX: find a better, readable, example
|
||||||
|
|
||||||
|
@ -536,7 +539,6 @@ expect a function argument.
|
||||||
method. Dictionaries accept any hashable value. Lists, tuples, and
|
method. Dictionaries accept any hashable value. Lists, tuples, and
|
||||||
strings accept an index or a slice:
|
strings accept an index or a slice:
|
||||||
|
|
||||||
>>> from operator import itemgetter
|
|
||||||
>>> itemgetter(1)('ABCDEFG')
|
>>> itemgetter(1)('ABCDEFG')
|
||||||
'B'
|
'B'
|
||||||
>>> itemgetter(1,3,5)('ABCDEFG')
|
>>> itemgetter(1,3,5)('ABCDEFG')
|
||||||
|
|
Loading…
Reference in New Issue