这是我拥有的一个脚本,它读取 JSON 文件并将路由添加到图表
for route in data['routes']:
route = Route(route['ports'][0], route['ports'][1], route['distance'])
self.add_route(route)
route_2 = Route (route['ports'][1], route['ports'][0], route['distance'])
self.add_route(route_2)
它给了我这个错误:
Traceback (most recent call last):
File "C:\workspace\Assignment2.1\src\Main.py", line 75, in <module>
graph.build_from_file()
File "C:\workspace\Assignment2.1\src\Graph.py", line 195, in build_from_file
route_2 = Route (route['ports'][1], route['ports'][0], route['distance'])
TypeError: 'Route' object is not subscriptable
请注意,它在第二次调用 Route 构造函数时出现错误,而不是第一次。谁能帮我解决这个问题?