刚刚看sumo的官方教程,有一段代码是生成配置文件,发现python中的print函数也可以写文件。

    with open("data/cross.rou.xml", "w") as routes:
        print("""<routes>
        <vType  \
guiShape="passenger"/>
        <vType />

        <route  />
        <route  />
        <route , file=routes)

其中三引号的作用之前文章写过,是为了保证代码中的换行效果能正常导出

Python中单引号、双引号、三引号的区别

相关文章:

  • 2021-03-31
  • 2022-12-23
  • 2021-06-05
  • 2021-08-19
  • 2021-08-05
  • 2022-12-23
猜你喜欢
  • 2021-10-03
  • 2022-12-23
  • 2022-12-23
  • 2021-10-21
  • 2021-08-16
相关资源
相似解决方案