如何删除Python中文本文件的文件内容?

在python中:

open('file.txt', 'w').close()

或者,如果你已经打开了一个文件:

f = open('file.txt', 'r+')
f.truncate(0) # need '0' when using r+

 

 
posted @ 2020-02-07 13:46  月夜_1  阅读(12470)  评论(0编辑  收藏  举报