使用python,如何从第七行开始读取文件? [英] Using python, how to read a file starting at the seventh line ?
本文介绍了使用python,如何从第七行开始读取文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文本文件结构:
I have a text file structure as:
date
downland
user
date data1 date2
201102 foo bar 200 50
201101 foo bar 300 35
所以不需要前六行文件。文件名:dnw.txt
So first six lines of file are not needed. filename:dnw.txt
f = open('dwn.txt', 'rb')
如何将第7行开始的文件拆分为EOF?
How do I "split" this file starting at line 7 to EOF?
推荐答案
with open('dwn.txt') as f:
for i in xrange(6):
f.next()
for line in f:
process(line)
这篇关于使用python,如何从第七行开始读取文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文