Python menghapus konten file
f = open('file.txt', 'r+')
f.truncate(0)
Horrible Hornet
f = open('file.txt', 'r+')
f.truncate(0)
#one way is to open the file for writing
file = open("sample.txt","w")
file.close()
#another way
file = open("example.txt","r+")
file.truncate(0)
file.close()
file = open("FILE_NAME.txt", "w+") # opens the file in both read and write mode
open('file.txt', 'w').close()