Python清空文本内容的两种方法

方法一:

file = open("test.txt", 'w').close()

 

直接清空“test.txt”里面的内容

方法二:

with open("test.txt", 'r+') as file:

  file.truncate(0)

 

posted @ 2020-03-19 20:30  profesor  阅读(31894)  评论(0编辑  收藏  举报