python empty file code example
Example 1: python empty text file
open('file.txt', 'w').close()
Example 2: python check if a file is empty
import os
if os.stat("yourfile.extension").st_size == 0:
#note: file has to be in same directory as python script#
print('empty')
Example 3: python os make empty file
open(x, 'a').close()
Example 4: how to empty a text file in python
file = open("sample.txt","r+")
file.truncate(0)
file.close()