Correct way to write line to file?

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

    In Python 3 it is a function, but in Python 2 you can add this to the top of the source file:

    from __future__ import print_function
    

    Then you do

    print("hi there", file=f)
    

提交回复
热议问题