File tree Expand file tree Collapse file tree 3 files changed +46
-1
lines changed Expand file tree Collapse file tree 3 files changed +46
-1
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ class Saveable(metaclass=ABCMeta):
6
6
def save (self ):
7
7
Database .insert (self .to_dict ())
8
8
9
- @abstractmethod
9
+ # @classmethod (or @staticmethod, or @property)
10
+ @abstractmethod # @abstractmethod must always be the innermost decorator if used in conjunction with other decorators.
10
11
def to_dict ():
11
12
pass
Original file line number Diff line number Diff line change
1
+ from flight import Segment , Flight
2
+
3
+
4
+ seg = [Segment ('EDI' , 'LHR' ), Segment ('LHR' , 'CAN' )]
5
+ flight = Flight (seg )
6
+
7
+ print (flight .departure_point )
8
+ print (flight )
9
+
10
+ flight .departure_point = 'GLA'
11
+ print ('...Set departure to GLA...' )
12
+
13
+ print (flight .departure_point )
14
+ print (flight )
Original file line number Diff line number Diff line change
1
+ class Flight :
2
+ def __init__ (self , segments ):
3
+ """
4
+
CB26
Creates a new Flight wrapper object from an arbitrary number of segments.
5
+
6
+ :param segments: a list of segments in this flight—normally just one.
7
+ """
8
+ self .segments = segments
9
+
10
+ def __repr__ (self ):
11
+ stops = [self .segments [0 ].departure , self .segments [0 ].destination ]
12
+ for seg in self .segments [1 :]:
13
+ stops .append (seg .destination )
14
+
15
+ return ' -> ' .join (stops )
16
+
17
+ @property
18
+ def departure_point (self ):
19
+ return self .segments [0 ].departure
20
+
21
+ @departure_point .setter
22
+ def departure_point (self , val ):
23
+ dest = self .segments [0 ].destination
24
+ self .segments [0 ] = Segment (departure = val , destination = dest )
25
+
26
+
27
+ class Segment :
28
+ def __init__ (self , departure , destination ):
29
+ self .departure = departure
30
+ self .destination = destination
You can’t perform that action at this time.
0 commit comments