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

在python中:

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

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

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