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