[英]How i can Read text file from a specific line in python?
我想讀取文本文件中第 5 行到 rest 的行。
文本文件包含。
第1行 第2行 第3行 第4行 第5行 第6行 第7行 第8行 第9行 第10行
我需要這樣的結果。 第 5 行 第 6 行 第 7 行 第 8 行 第 9 行 第 10 行
在 for 循環中使用enumerate
來計算行數
lines_after_five =[]
with open("file.txt") as fp:
for i, line in enumerate(fp):
if i >= 5:
print(line)
lines_after_five.append(line)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.