1# Delete all text in a text file
2f = open("text_file.txt", "r+")
3f.truncate(0)
4f.close()
1#get list of lines.
2a_file = open("sample.txt", "r")
3lines = a_file. readlines()
4a_file. close()
5#remove line from list
6del lines[1] delete lines.
7#write new contents into file
8new_file = open("sample.txt", "w+") write to file without line.
9for line in lines:
10new_file. write(line)
11new_file. close()