MCPcopy Create free account
hub / github.com/bslatkin/effectivepython / Toaster

Class Toaster

example_code/item_109.py:51–70  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49
50print("Example 1")
51class Toaster:
52 def __init__(self, timer):
53 self.timer = timer
54 self.doneness = 3
55 self.hot = False
56
57 def _get_duration(self):
58 return max(0.1, min(120, self.doneness * 10))
59
60 def push_down(self):
61 if self.hot:
62 return
63
64 self.hot = True
65 self.timer.countdown(self._get_duration(), self.pop_up)
66
67 def pop_up(self):
68 print("Pop!") # Release the spring
69 self.hot = False
70 self.timer.end()
71
72
73print("Example 2")

Callers 5

item_109.pyFile · 0.85
test_startMethod · 0.85
test_endMethod · 0.85
setUpMethod · 0.85
setUpMethod · 0.85

Calls

no outgoing calls

Tested by 2

test_startMethod · 0.68
test_endMethod · 0.68