从python中的某一行开始读取(Reading from a certain line onwards in python)

编程入门 行业动态 更新时间:2024-10-19 18:15:51
从python中的某一行开始读取(Reading from a certain line onwards in python)

是否可以从某一行开始读取? 在下面引用的示例中,我只想从Line04开始阅读和使用

with open (fileList[0], 'rt') as filehandle: for line in filehandle: print line # Output: # This is a testing file # # v 1.05 # v -2.15

Is it possible to read from a certain line onwards? In the example I cited below, I had want to read and use only from Line04 onwards

with open (fileList[0], 'rt') as filehandle: for line in filehandle: print line # Output: # This is a testing file # # v 1.05 # v -2.15

最满意答案

这应该工作:

with open('your_file', 'rt') as filehandle: lines = filehandle.readlines()[4:] for line in lines: print line #do something

This should work:

with open('your_file', 'rt') as filehandle: lines = filehandle.readlines()[4:] for line in lines: print line #do something

更多推荐

本文发布于:2023-08-07 02:33:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1458506.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Reading   python   onwards   line

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!