words_Deque类不起作用。 我正在尝试使words_Deque类可以将单词转移到Deque类中。
class Deque:
def __init__(self):
self.items = []
def add_front(self, item):
self.items.insert(0, item)
def add_rear(self, item):
self.items.append(item)
def remove_front(self):
if self.items:
return self.items.pop(0)
return None
def remove_rear(self):
if self.items:
return self.items.pop()
return None
class words_Deque:
def __init__(self, words, deque):
self.words = words
self.deque = deque
def transfer(self, deque):
for word in self.words:
print(word)
deque.add_rear(word)
a = Deque()
words_Deque('mom', a)
words_Deque.transfer(a)
print(a.items)
预期输出:['m','o','m'] 实际结果:transfer()缺少1个必需的位置参数:'deque'
答案 0 :(得分:0)
您正在调用传输方法,因为它是一个类方法。但是,它是一个实例方法。因此,您必须在实例上调用它。尝试这种方式:
`
p1=(49.338202, -123.142030)
p2=(49.335271, -123.125171)
p3=(49.332503, -123.116240)
p4=(49.332447, -123.104249)
p5=(49.331949, -123.092218)
p6=(49.331996, -123.077877)
p7=(49.329556, -123.054275)
p8=(49.326069, -123.048102)
p9=(49.312711, -123.030485)
p10=(49.306328, -123.028022)
p11=(49.291653, -123.026348)
directions_results1 = gmaps.distance_matrix(p1,p2,mode="driving",units="metric",departure_time=now,traffic_model= "best_guess")
directions_results2 = gmaps.distance_matrix(p2,p3,mode="driving",units="metric",departure_time=now,traffic_model= "best_guess")
directions_results3 = gmaps.distance_matrix(p3,p4,mode="driving",units="metric",departure_time=now,traffic_model= "best_guess")
directions_results4 = gmaps.distance_matrix(p4,p5,mode="driving",units="metric",departure_time=now,traffic_model= "best_guess")
directions_results5 = gmaps.distance_matrix(p5,p6,mode="driving",units="metric",departure_time=now,traffic_model= "best_guess")
directions_results6 = gmaps.distance_matrix(p6,p7,mode="driving",units="metric",departure_time=now,traffic_model= "best_guess")
directions_results7 = gmaps.distance_matrix(p7,p8,mode="driving",units="metric",departure_time=now,traffic_model= "best_guess")
directions_results8 = gmaps.distance_matrix(p8,p9,mode="driving",units="metric",departure_time=now,traffic_model= "best_guess")
directions_results9 = gmaps.distance_matrix(p9,p10,mode="driving",units="metric",departure_time=now,traffic_model= "best_guess")
directions_results10 = gmaps.distance_matrix(p10,p11,mode="driving",units="metric",departure_time=now,traffic_model= "best_guess")
directions_resultst = gmaps.distance_matrix(p1,p11,mode="driving",units="metric",departure_time=now,traffic_model= "best_guess")
the number is in second
Output
Segment 1 Time: 149
Segment 2 Time: 37
Segment 3 Time: 63
Segment 4 Time: 49
Segment 5 Time: 49
Segment 6 Time: 96
Segment 7 Time: 35
Segment 8 Time: 141
Segment 9 Time: 134
Segment 10 Time: 134
Sum of Time required for all Segments: 887
Time required from First point to Last point: 1084
`
这将产生正确的输出
a = Deque()
b = words_Deque('mom', a) # save your instance as b
b.transfer(a)
print(a.items)