我有一些txt文件。我试图遍历该txt文件集合,并从每个文件中打印第6行和第10行。但是,在我的代码中仅打印第一行。如何获得第二行(用于islice中的行)进行打印?
import glob2
import csv
from pathlib import Path
from itertools import islice
folder = r"C:\Users\test"
p = Path(folder)
txt_list = list(p.glob('*.txt'))
for i in txt_list:
print(f"User:{i.stem}; Start date:")
with open(i) as fin:
for line in islice(fin, 6, 7):
print(line[0:10])
for line in islice(fin, 10, 11):
print(line[0:10])