Correct way to write line to file?

后端 未结 14 1931
日久生厌
日久生厌 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:46

    You can also try filewriter

    pip install filewriter

    from filewriter import Writer
    
    Writer(filename='my_file', ext='txt') << ["row 1 hi there", "row 2"]
    

    Writes into my_file.txt

    Takes an iterable or an object with __str__ support.

提交回复
热议问题