[Python] 跳过前几行快速读取文件内容:islice
from itertools import islice start = 1 # 跳过第一行idx=0,从idx=1开始读取文件 with codecs.open('data.json', encoding='utf-8') as fr: for idx, line in enumerate(islice(fr, start, None)): print idx, line
from itertools import islice start = 1 # 跳过第一行idx=0,从idx=1开始读取文件 with codecs.open('data.json', encoding='utf-8') as fr: for idx, line in enumerate(islice(fr, start, None)): print idx, line