使用
itertools.islice:
import itertoolswith open(pth_file) as f: for line in itertools.islice(f, 1, None, 2): # 1: from the second line ([1]) # None: to the end # 2: step # Do something with the line

使用
itertools.islice:
import itertoolswith open(pth_file) as f: for line in itertools.islice(f, 1, None, 2): # 1: from the second line ([1]) # None: to the end # 2: step # Do something with the line