【发布时间】:2022-01-08 11:45:23
【问题描述】:
我正在尝试解决这个问题。我想要的输出是用值打印字典; “Trasa”的名称和每个 Warszawa1 Warszawa 2 等的列表。为此,我创建了第二个函数:stat_info。当前输出:{'Name and information': ['Ko', <function station.stat_info at 0x7fe4dbbe3040>]} 所需输出:{'Name and information': ['Ko',[Warszawa1, Warszawa 2 etc.]
我的代码:
class station:
def __init__(self, name, possibility_of_change, time_of_stay):
self.name = name
self.possibility_of_change = possibility_of_change
self.time_of_stay = time_of_stay
stat = []
stat.append(self.name)
self.stat = stat
def stat_info(self):
return self.stat
class Position_of_route:
def __init__(self, station, time_between_2_stays):
self.station = station
self.time_between_2_stays = time_between_2_stays
class Route(station):
def __init__(self, name1, list_of_positions):
self.name1 = name1
self.list_of_postitions = list_of_positions
def trasa_info(self):
return 5
def generate(self, time):
przystanki = [
station("Warszawa1",True,3),
station("Warszawa2",True,5),
station("Warszawa3",False,0),
station("Warszawa4",True,3),
station("Warszawa5",True,7),
station("Warszawa6",True,3),
station("Warszawa7",True,9),
station("Warszawa8",False,0),
station("Warszawa9",True,12),
]
a={
"Name and information": [self.name1,station.stat_info]
}
return a
print(Route("Ko",[1,2]).generate(18))
【问题讨论】:
标签: python list function class