]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Move the namedtuple class definition to the end of the example.
authorRaymond Hettinger <python@rcn.com>
Sat, 27 Feb 2010 07:05:37 +0000 (07:05 +0000)
committerRaymond Hettinger <python@rcn.com>
Sat, 27 Feb 2010 07:05:37 +0000 (07:05 +0000)
Doc/library/collections.rst

index 117059ac0b208fcbee58e6746db757099c07def1..6f5e1003a13d59f892cf0e816a5e6be2c49c7cc6 100644 (file)
@@ -505,7 +505,19 @@ Example:
 .. doctest::
    :options: +NORMALIZE_WHITESPACE
 
-   >>> Point = namedtuple('Point', 'x y', verbose=True)
+   >>> Point = namedtuple('Point', 'x y')
+   >>> p = Point(11, y=22)     # instantiate with positional or keyword arguments
+   >>> p[0] + p[1]             # indexable like the plain tuple (11, 22)
+   33
+   >>> x, y = p                # unpack like a regular tuple
+   >>> x, y
+   (11, 22)
+   >>> p.x + p.y               # fields also accessible by name
+   33
+   >>> p                       # readable __repr__ with a name=value style
+   Point(x=11, y=22)
+
+   >>> Point = namedtuple('Point', 'x y', verbose=True) # show the class definition
    class Point(tuple):
            'Point(x, y)'
    <BLANKLINE>
@@ -544,17 +556,6 @@ Example:
            x = _property(_itemgetter(0))
            y = _property(_itemgetter(1))
 
-   >>> p = Point(11, y=22)     # instantiate with positional or keyword arguments
-   >>> p[0] + p[1]             # indexable like the plain tuple (11, 22)
-   33
-   >>> x, y = p                # unpack like a regular tuple
-   >>> x, y
-   (11, 22)
-   >>> p.x + p.y               # fields also accessible by name
-   33
-   >>> p                       # readable __repr__ with a name=value style
-   Point(x=11, y=22)
-
 Named tuples are especially useful for assigning field names to result tuples returned
 by the :mod:`csv` or :mod:`sqlite3` modules::