remove everything in a file python code example
Example 1: how to delete everything on a file python
f = open('file.txt', 'r+')
f.truncate(0) # need '0' when using r+
Example 2: python delete contents of file
open('file.txt', 'w').close()
f = open('file.txt', 'r+')
f.truncate(0) # need '0' when using r+
open('file.txt', 'w').close()