MCPcopy Create free account
hub / github.com/dabeaz/python-cookbook / House

Class House

src/8/making_classes_support_comparison_operations/example.py:10–32  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8
9@total_ordering
10class House:
11 def __init__(self, name, style):
12 self.name = name
13 self.style = style
14 self.rooms = list()
15
16 @property
17 def living_space_footage(self):
18 return sum(r.square_feet for r in self.rooms)
19
20 def add_room(self, room):
21 self.rooms.append(room)
22
23 def __str__(self):
24 return '{}: {} square foot {}'.format(self.name,
25 self.living_space_footage,
26 self.style)
27
28 def __eq__(self, other):
29 return self.living_space_footage == other.living_space_footage
30
31 def __lt__(self, other):
32 return self.living_space_footage < other.living_space_footage
33
34
35

Callers 1

example.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected