0

I have program that is turning sensor measurements into a .xyz file. To do this, it has to write to the file in the form x y z \n I'm using the following line of code

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

xpos and zpos are both floats

I was expecting the output to the file to be

xpos 0 zpos

but instead i'm getting

xpos 0 xpos

I'm not sure why, and I'm not sure any alternative to using format either.

PM 77-1
  • 12,933
  • 21
  • 68
  • 111

2 Answers2

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

An alternative is:

 f.write(str(xpos) +' 0 '+str(zpos)+'\n') 
Nandu Raj
  • 2,072
  • 9
  • 20
0

I think you can do it that way.

f.write(f"{xpos} 0 {ypos}")
Raamyy
  • 560
  • 1
  • 6
  • 15