]> granicus.if.org Git - python/commitdiff
Cleanup subclassing example to more clearly show fixed-width print format.
authorRaymond Hettinger <python@rcn.com>
Mon, 7 Jan 2008 05:50:35 +0000 (05:50 +0000)
committerRaymond Hettinger <python@rcn.com>
Mon, 7 Jan 2008 05:50:35 +0000 (05:50 +0000)
Doc/library/collections.rst
Lib/collections.py

index 1f9e82dc7023926a969c49052b901d0121836522..d7d1083738c2da5984484fcf0205f23a01b251ca 100644 (file)
@@ -511,7 +511,7 @@ When casting a dictionary to a named tuple, use the double-star-operator [#]_::
 
 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 custom fixed-width print format:
+a fixed-width print format:
 
 ::
 
@@ -522,10 +522,10 @@ a custom fixed-width print format:
         def __repr__(self):
             return 'Point(x=%.3f, y=%.3f, hypot=%.3f)' % (self.x, self.y, self.hypot)
 
-    >>> print Point(3, 4)
-    Point(x=3.000, y=4.000, hypot=5.000)
-    >>> Point(2, 5)
-    Point(x=2.000, y=5.000, hypot=5.385)
+    >>> print Point(3, 4),'\n', Point(2, 5), '\n', Point(9./7, 6)
+    Point(x=3.000, y=4.000, hypot=5.000) 
+    Point(x=2.000, y=5.000, hypot=5.385) 
+    Point(x=1.286, y=6.000, hypot=6.136)
 
 Default values can be implemented by starting with a prototype instance
 and customizing it with :meth:`_replace`:
index 1701952cde7c22dc97696c83785f5f3f1e75d9e4..d3f7b80caf8dccd541060e09da34fb540dfbe1bb 100644 (file)
@@ -123,8 +123,7 @@ if __name__ == '__main__':
         def __repr__(self):
             return 'Point(x=%.3f, y=%.3f, hypot=%.3f)' % (self.x, self.y, self.hypot)
 
-    print Point(3, 4)
-    print Point(2, 5)
+    print Point(3, 4),'\n', Point(2, 5), '\n', Point(9./7, 6)
 
     import doctest
     TestResults = namedtuple('TestResults', 'failed attempted')