📅  最后修改于: 2022-03-11 14:46:54.396000             🧑  作者: Mango
#get list of lines.
a_file = open("sample.txt", "r")
lines = a_file. readlines()
a_file. close()
#remove line from list
del lines[1] delete lines.
#write new contents into file
new_file = open("sample.txt", "w+") write to file without line.
for line in lines:
new_file. write(line)
new_file. close()