dtect empty text from file python code example Example: how to empty a text file in python file = open("sample.txt","r+") file.truncate(0) file.close()