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