writing integer values to a file using out.write()

前端 未结 4 653
忘了有多久
忘了有多久 2021-02-05 04:48

I am generating some numbers(lets say, num) and writing the numbers to output file using outf.write(num).
But compiler is throwing an error:

         


        
4条回答
  •  一个人的身影
    2021-02-05 05:07

    Also you can use f-string formatting to write integer to file

    For appending use following code, for writing once replace 'a' with 'w'.

    for i in s_list:
        with open('path_to_file','a') as file:
            file.write(f'{i}\n')
    
    file.close()
    

提交回复
热议问题