diff options
author | Raymond Hettinger <python@rcn.com> | 2008-01-07 20:07:38 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2008-01-07 20:07:38 (GMT) |
commit | 9a359210aaa7d9e0aa85f5a2084e7665bf0dae25 (patch) | |
tree | afdc017d75bdcfec0853230c997eba5200edf14d /Lib/collections.py | |
parent | 4d7e6702e96f7c681ca4ad7104269d9efa51d9f9 (diff) | |
download | cpython-9a359210aaa7d9e0aa85f5a2084e7665bf0dae25.zip cpython-9a359210aaa7d9e0aa85f5a2084e7665bf0dae25.tar.gz cpython-9a359210aaa7d9e0aa85f5a2084e7665bf0dae25.tar.bz2 |
Cleanup named tuple subclassing example.
Diffstat (limited to 'Lib/collections.py')
-rw-r--r-- | Lib/collections.py | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/Lib/collections.py b/Lib/collections.py index 51184a4..c19821b 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' |