how to delete anything in a txt file py code example Example: python delete all data from file file = open("sample.txt","r+") file.truncate(0) file.close()