How to delete only the content of file in python

后端 未结 4 1353
無奈伤痛
無奈伤痛 2020-12-13 09:48

I have a temporary file with some content and a python script generating some output to this file. I want this to repeat N times, so I need to reuse that file (actually arra

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-13 10:00

    You can do this:

    def deleteContent(pfile):
        fn=pfile.name 
        pfile.close()
        return open(fn,'w')
    

提交回复
热议问题