[Python-checkins] r59815 - python/trunk/Doc/library/collections.rst

Raymond Hettinger python at rcn.com
Mon Jan 7 10:40:53 CET 2008


Please revert the part with "somenamedtuple".  That was not a typo, it is distinct from namedtuple() which is a factory function 
which returns a new class.  The moniker, somenamedtuple refers to a instance of that created class.




----- Original Message ----- 
From: "georg.brandl" <python-checkins at python.org>
To: <python-checkins at python.org>
Sent: Monday, January 07, 2008 1:18 AM
Subject: [Python-checkins] r59815 - python/trunk/Doc/library/collections.rst


> Author: georg.brandl
> Date: Mon Jan  7 10:18:17 2008
> New Revision: 59815
>
> Modified:
>   python/trunk/Doc/library/collections.rst
> Log:
> Clean up markup.
>
>
> Modified: python/trunk/Doc/library/collections.rst
> ==============================================================================
> --- python/trunk/Doc/library/collections.rst (original)
> +++ python/trunk/Doc/library/collections.rst Mon Jan  7 10:18:17 2008
> @@ -458,7 +458,7 @@
>       >>> Point._make(t)
>       Point(x=11, y=22)
>
> -.. method:: somenamedtuple._asdict()
> +.. method:: namedtuple._asdict()
>
>    Return a new dict which maps field names to their corresponding values:
>
> @@ -467,7 +467,7 @@
>       >>> p._asdict()
>       {'x': 11, 'y': 22}
>
> -.. method:: somenamedtuple._replace(kwargs)
> +.. method:: namedtuple._replace(kwargs)
>
>    Return a new instance of the named tuple replacing specified fields with new values:
>
> @@ -480,7 +480,7 @@
>       >>> for partnum, record in inventory.items():
>       ...     inventory[partnum] = record._replace(price=newprices[partnum], updated=time.now())
>
> -.. attribute:: somenamedtuple._fields
> +.. attribute:: namedtuple._fields
>
>    Tuple of strings listing the field names.  This is useful for introspection
>    and for creating new named tuple types from existing named tuples.
> @@ -511,9 +511,7 @@
>
> Since a named tuple is a regular Python class, it is easy to add or change
> functionality with a subclass.  Here is how to add a calculated field and
> -a fixed-width print format:
> -
> -::
> +a fixed-width print format::
>
>     >>> class Point(namedtuple('Point', 'x y')):
>         @property
> @@ -528,7 +526,7 @@
>     Point(x=1.286, y=6.000, hypot=6.136)
>
> Another use for subclassing is to replace performance critcal methods with
> -faster versions that bypass error-checking and localize variable access:
> +faster versions that bypass error-checking and localize variable access::
>
>     >>> class Point(namedtuple('Point', 'x y')):
>         _make = classmethod(tuple.__new__)
> _______________________________________________
> Python-checkins mailing list
> Python-checkins at python.org
> http://mail.python.org/mailman/listinfo/python-checkins 


More information about the Python-checkins mailing list