[Python-checkins] r61766 - python/trunk/Doc/library/operator.rst

georg.brandl python-checkins at python.org
Sat Mar 22 22:26:44 CET 2008


Author: georg.brandl
Date: Sat Mar 22 22:26:44 2008
New Revision: 61766

Modified:
   python/trunk/Doc/library/operator.rst
Log:
Test doctests in operator docs.


Modified: python/trunk/Doc/library/operator.rst
==============================================================================
--- python/trunk/Doc/library/operator.rst	(original)
+++ python/trunk/Doc/library/operator.rst	Sat Mar 22 22:26:44 2008
@@ -415,7 +415,7 @@
 
    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 @@
       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 @@
    
    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 @@
       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)


More information about the Python-checkins mailing list