Write to a file from a list with integer Python

后端 未结 3 1441
梦如初夏
梦如初夏 2021-01-23 17:18

Im trying to write a text file from a list, it works perfectly with a list of strings, each element gets on a new line. But when I try to write from a list with integers it does

3条回答
  •  粉色の甜心
    2021-01-23 17:46

    You need to convert the integers to strings.

    with open('year_string.txt', 'w') as file:
    file.write('\n'.join(year_string))
    

    Needs to be:

    with open('year_string.txt', 'w') as file:
    file.write(str('\n'.join(year_string)))
    

提交回复
热议问题