Correct way to write line to file?

后端 未结 14 1963
日久生厌
日久生厌 2020-11-21 06:27

I\'m used to doing print >>f, \"hi there\"

However, it seems that print >> is getting deprecated. What is the recommended way t

14条回答
  •  一个人的身影
    2020-11-21 06:45

    One can also use the io module as in:

    import io
    my_string = "hi there"
    
    with io.open("output_file.txt", mode='w', encoding='utf-8') as f:
        f.write(my_string)
    

提交回复
热议问题