Home  »  CodeSnippets   »   Python Delete all Text in Text File

Python Delete all Text in Text File

Posted: February 6, 2022 | by Michael Bright

f = open("filename.txt", "r+")
f.truncate(0)
f.close()

Found this article interesting? Follow Brightwhiz on Facebook, Twitter, and YouTube to read and watch more content we post.