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

在python中:

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

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

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

猜你喜欢

转载自www.cnblogs.com/zb-ml/p/12272807.html
今日推荐