#!/usr/bin/env python3 from pyswip import Prolog swipl = Prolog() swipl.consult("trains.pl") STATIONS = [ans["S"] for ans in swipl.query("station(S)")] def route_length(From, To): return next(swipl.query(f"route_length({From}, {To}, L)"))["L"] def main(): for station in STATIONS: print(station) print(route_length(STATIONS[0], STATIONS[1])) if __name__ == "__main__": main()