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

raymond.hettinger python-checkins at python.org
Thu Nov 15 23:39:34 CET 2007


Author: raymond.hettinger
Date: Thu Nov 15 23:39:34 2007
New Revision: 58998

Modified:
   python/trunk/Doc/library/collections.rst
Log:
Add example for use cases requiring default values.

Modified: python/trunk/Doc/library/collections.rst
==============================================================================
--- python/trunk/Doc/library/collections.rst	(original)
+++ python/trunk/Doc/library/collections.rst	Thu Nov 15 23:39:34 2007
@@ -492,6 +492,15 @@
     >>> Point(x=10, y=20)
     Point(10.000, 20.000)
 
+Default values can be implemented by starting with a prototype instance
+and customizing it with :meth:`__replace__`:
+
+::
+
+    >>> Account = namedtuple('Account', 'owner balance transaction_count')
+    >>> model_account = Account('<owner name>', 0.0, 0)
+    >>> johns_account = model_account.__replace__(owner='John')
+
 .. rubric:: Footnotes
 
 .. [#] For information on the star-operator see


More information about the Python-checkins mailing list