python清空文件内容

text_path="/xxx/xxx"
def clear():
with open(text_path, 'w') as f1:
f1.seek(0)
f1.truncate()
print("清空数据")

clear()

原文地址:https://www.cnblogs.com/ss0202go/p/13157641.html