且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Python文件中读取行时跳过第一行

更新时间:2023-09-17 23:33:04

使用切片,如下所示

with open('yourfile.txt') as f:
    lines_after_17 = f.readlines()[17:]






如果文件太大量加载内存:


If the file is too big to load in memory:

with open('yourfile.txt') as f:
    for _ in xrange(17):
        next(f)
    for line in f:
        # do stuff