Search code examples
pythonsumo

How to deal in python with the xml files preceded by the TIME prefix in successive runs of SUMO


I want to get the results of a SUMO successive runs in CSV format directly by using python script (not by using the xml2csv tools and cmd). Due to the TIME prefix comes before the XML file, I don't know how to deal with this part of the code. Here we want the run to show the results separately by using the time: sumoCmd = [sumoBinary, "-c", "test4.sumocfg", "--tripinfo-output", "tripinfo.xml", "--output-prefix", " TIME"]. And here is where I must put the proper XML file name which is my question: tree = ET.parse("myfile.xml")

Any help would be appreciated. Best, Ali


Solution

  • You can just find the file using glob e.g.:

    import glob
    tripinfos = glob.glob("*tripinfo.xml")
    

    To get the latest you can use sorted:

    latest = sorted(tripinfos)[-1]
    tree = ET.parse(latest)