首页 > 编程语言 > 详细

python读取特定的行

时间:2016-06-22 17:17:12      阅读:244      评论:0      收藏:0      [点我收藏+]
fr = open(filename)
for line in fr.readlines():
    if line.startswith("#"):
        continue
    else:
        ## do something with line
        
## could use fr.readlines()[1:]  from second line

import linecache
content_list = linecache.getlines(filename)[1:]     ## Here using getlines

fourth_line = linecache.getline(filename, 4)        ## Here using getline
## the above method is simpler.


python读取特定的行

原文:http://matrix6ro.blog.51cto.com/1746429/1791788

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!