November 2018
Beginner
304 pages
7h 35m
English
Gate valves are children of the parent Valve class, as shown in the following code example:
# valve.py (part 8)1 class Gate(Valve):
2 """Open/closed valve."""
3 def read_position(self):
4 """Identify the position of the valve."""
5 if self.position == 0:
6 return "{name} is closed.".format(name=self.name)
7 elif self.position == 100:
8 return "{name} is open.".format(name=self.name)
9 else: # bad condition
10 return "Warning! {name} is partially open.".format(name=self.name)
11
12 def turn_handle(self, new_position):
13 """Change the status of the valve."""
14 if new_position == 0:
15 self.close()
16 elif new_position == 100:
17 self.open()
18 else: # Shouldn't get here
19 return "Warning: Invalid valve position."
The
Read now
Unlock full access