Issue 6722: Improve the namedtuple examples.

This commit is contained in:
Raymond Hettinger 2010-11-21 23:23:29 +00:00
parent 086f30815c
commit 0ef956f997

View file

@ -586,11 +586,15 @@ they add the ability to access fields by name instead of position index.
.. versionchanged:: 3.1 .. versionchanged:: 3.1
Added support for *rename*. Added support for *rename*.
Example:
.. doctest:: .. doctest::
:options: +NORMALIZE_WHITESPACE :options: +NORMALIZE_WHITESPACE
>>> # Basic example
>>> Point = namedtuple('Point', 'x y')
>>> p = Point(x=10, y=11)
>>> # Example using the verbose option to print the class definition
>>> Point = namedtuple('Point', 'x y', verbose=True) >>> Point = namedtuple('Point', 'x y', verbose=True)
class Point(tuple): class Point(tuple):
'Point(x, y)' 'Point(x, y)'