Search code examples
pythonpython-2.7formattingcarriage-return

python 2 print array with float formatting and without line return


I am using Python 2.7 I ran into this formatting problem when trying to output some debug data. I want to print only 5 decimal, have all result on the same line and separated by a tab

for index in range(NBR):
  print("%.5f\t," % (result[line, index]))

and it resulted in

5.68842,    
4.29441,    
6.27793,    

while i wanted

5.68842    4.29441    6.27793

Any advise on how to remove this unwanted return line?


Solution

  • It's alright, i found the solution. it was simply missing the coma ',' at the end of the line and not within the string

    print("%.5f\t" % (result[line, index])),