【问题标题】:Using format In python not working (Beginner Question)在 python 中使用格式不起作用(初学者问题)
【发布时间】:2020-07-19 04:13:56
【问题描述】:

我有将传感器测量值转换为 .xyz 文件的程序。 为此,它必须以 x y z \n 的形式写入文件 我正在使用以下代码行

f.write('{0:f} 0 {0:f}\n'.format(xpos,zpos))

xposzpos 都是浮点数

我希望文件的输出是

xpos 0 zpos

但是我得到了

xpos 0 xpos

我不知道为什么,我也不确定使用格式的任何替代方法。

【问题讨论】:

    标签: python coordinates xyz


    【解决方案1】:
    f.write('{0:f} 0 {1:f}\n'.format(xpos,zpos))
    

    另一种选择是:

     f.write(str(xpos) +' 0 '+str(zpos)+'\n') 
    

    【讨论】:

      【解决方案2】:

      我认为你可以这样做。

      f.write(f"{xpos} 0 {ypos}")
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-09-21
        • 2011-08-17
        • 1970-01-01
        • 2021-07-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多