📌  相关文章
📜  在 python 代码示例中删除文本文件

📅  最后修改于: 2022-03-11 14:46:54.396000             🧑  作者: Mango

代码示例2
#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()