如何通过python删除文本文件中的所有字符

0 python python-3.x

我有一个文字文件namefile.txt,有更多的性格.我想删除所有文本并保留文件,以便namefile.txt在运行python脚本后打开时看到nothings ?

Eyu*_*lDK 5

这样做.从概念上打开具有写入权限的文件会清除以前的数据.

open('namefile.txt', 'w').close()
Run Code Online (Sandbox Code Playgroud)