MCPcopy Create free account
hub / github.com/ActiveState/code / Point

Class Point

recipes/Python/500261_Named_Tuples/recipe-500261.py:127–132  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

125
126 # test and demonstrate ability to override methods
127 class Point(namedtuple('Point', 'x y')):
128 @property
129 def hypot(self):
130 return (self.x ** 2 + self.y ** 2) ** 0.5
131 def __str__(self):
132 return 'Point: x=%6.3f y=%6.3f hypot=%6.3f' % (self.x, self.y, self.hypot)
133
134 for p in Point(3,4), Point(14,5), Point(9./7,6):
135 print p

Callers 1

recipe-500261.pyFile · 0.70

Calls 2

namedtupleFunction · 0.70
classmethodFunction · 0.50

Tested by

no test coverage detected