我有一个这样的 textfile.txt:
First Line
Second Line
Third Line
Fourth Line
Fifth Line
Sixth Line
如何去掉前三行和最后一行最舒服?
最佳答案
with open('textfile.txt') as old, open('newfile.txt', 'w') as new:
lines = old.readlines()
new.writelines(lines[3:-1])
关于python - 从文本文件中删除行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2064184/