在python中:
open(‘file.txt‘, ‘w‘).close()
或者,如果你已经打开了一个文件:
f = open(‘file.txt‘, ‘r+‘) f.truncate(0) # need ‘0‘ when using r+
如何删除Python中文本文件的文件内容?
原文:https://www.cnblogs.com/zb-ml/p/12272807.html