summaryrefslogtreecommitdiff
path: root/Lib/collections.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2008-01-07 20:07:38 +0000
committerRaymond Hettinger <python@rcn.com>2008-01-07 20:07:38 +0000
commitd64c9888104578de466ef48ee6a0ba10be3504bf (patch)
tree6dc6e4217e223a72ab2f675d9932e5b47dcce136 /Lib/collections.py
parent65c565ba408f6a7cfda59fbdd7e96a7555b0af53 (diff)
downloadcpython-d64c9888104578de466ef48ee6a0ba10be3504bf.tar.gz
Cleanup named tuple subclassing example.
Diffstat (limited to 'Lib/collections.py')
-rw-r--r--Lib/collections.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/Lib/collections.py b/Lib/collections.py
index 51184a430b..c19821bb39 100644
--- a/Lib/collections.py
+++ b/Lib/collections.py
@@ -120,10 +120,11 @@ if __name__ == '__main__':
@property
def hypot(self):
return (self.x ** 2 + self.y ** 2) ** 0.5
- def __repr__(self):
- return 'Point(x=%.3f, y=%.3f, hypot=%.3f)' % (self.x, self.y, self.hypot)
+ def __str__(self):
+ return 'Point: x=%6.3f y=%6.3f hypot=%6.3f' % (self.x, self.y, self.hypot)
- print Point(3, 4),'\n', Point(2, 5), '\n', Point(9./7, 6)
+ for p in Point(3,4), Point(14,5), Point(9./7,6):
+ print p
class Point(namedtuple('Point', 'x y')):
'Point class with optimized _make() and _replace() without error-checking'