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