刚刚看sumo的官方教程,有一段代码是生成配置文件,发现python中的print函数也可以写文件。
with open("data/cross.rou.xml", "w") as routes: print("""<routes> <vType id="typeWE" accel="0.8" decel="4.5" sigma="0.5" length="5" minGap="2.5" maxSpeed="16.67" guiShape="passenger"/> <vType id="typeNS" accel="0.8" decel="4.5" sigma="0.5" length="7" minGap="3" maxSpeed="25" guiShape="bus"/> <route id="right" edges="51o 1i 2o 52i" /> <route id="left" edges="52o 2i 1o 51i" /> <route id="down" edges="54o 4i 3o 53i" />""", file=routes)
其中三引号的作用之前文章写过,是为了保证代码中的换行效果能正常导出
原文地址:https://www.cnblogs.com/roadwide/p/10399913.html
时间: 2024-11-08 03:04:52