diff options
author | Georg Brandl <georg@python.org> | 2008-03-22 21:26:44 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2008-03-22 21:26:44 (GMT) |
commit | 4f0f34f1315dd8281afa1e21f5a53b6fab9abab3 (patch) | |
tree | 35c5a3d8b1e17d24d0534c9316a8ede3205af934 /Doc | |
parent | 3f04303ba4f37402d5097f28783b4d972cb8fb92 (diff) | |
download | cpython-4f0f34f1315dd8281afa1e21f5a53b6fab9abab3.zip cpython-4f0f34f1315dd8281afa1e21f5a53b6fab9abab3.tar.gz cpython-4f0f34f1315dd8281afa1e21f5a53b6fab9abab3.tar.bz2 |
Test doctests in operator docs.
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/operator.rst | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/Doc/library/operator.rst b/Doc/library/operator.rst index 7986ca6..a2329e8 100644 --- a/Doc/library/operator.rst +++ b/Doc/library/operator.rst @@ -415,7 +415,7 @@ objects. Be careful not to misinterpret the results of these functions; only :func:`isCallable` has any measure of reliability with instance objects. - For example:: + For example: >>> class C: ... pass @@ -479,13 +479,14 @@ objects. useful than it otherwise might be. Example: Build a dictionary that maps the ordinals from ``0`` to ``255`` to -their character equivalents. :: +their character equivalents. >>> import operator >>> d = {} >>> keys = range(256) >>> vals = map(chr, keys) >>> map(operator.setitem, [d]*len(keys), keys, vals) + [None, None, ..., None] .. XXX: find a better, readable, example @@ -533,14 +534,15 @@ expect a function argument. The items can be any type accepted by the operand's :meth:`__getitem__` method. Dictionaries accept any hashable value. Lists, tuples, and - strings accept an index or a slice:: + strings accept an index or a slice: - >>> itemgetter(1)('ABCDEFG') - 'B' - >>> itemgetter(1,3,5)('ABCDEFG') - ('B', 'D', 'F') - >>> itemgetter(slice(2,None))('ABCDEFG') - 'CDEFG' + >>> from operator import itemgetter + >>> itemgetter(1)('ABCDEFG') + 'B' + >>> itemgetter(1,3,5)('ABCDEFG') + ('B', 'D', 'F') + >>> itemgetter(slice(2,None))('ABCDEFG') + 'CDEFG' .. versionadded:: 2.4 @@ -548,9 +550,8 @@ expect a function argument. Added support for multiple item extraction. Example of using :func:`itemgetter` to retrieve specific fields from a - tuple record:: + tuple record: - >>> from operator import itemgetter >>> inventory = [('apple', 3), ('banana', 2), ('pear', 5), ('orange', 1)] >>> getcount = itemgetter(1) >>> map(getcount, inventory) |