Python - Print items in list with neither commas nor apostrophes

后端 未结 2 1897
萌比男神i
萌比男神i 2021-01-25 14:30

Minimal working example of my code:

# Create output data file
out_data_file = open(\'output_file\',\'w\')
out_data_file.write(\"# Header \\n\")
out_data_file.clo         


        
2条回答
  •  无人及你
    2021-01-25 14:56

    f.write('Text'+'  '+' '.join('%d' % item for item in list1))
    

    Or, since it looks like you are OK with the default conversion of an integer to string:

    f.write('Text'+'  '+' '.join(str(item) for item in list1))
    

提交回复
热议问题