从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.15Is 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 somethingThis should work:
with open('your_file', 'rt') as filehandle: lines = filehandle.readlines()[4:] for line in lines: print line #do something更多推荐
发布评论