file - Reading specific lines only (Python) -
i'm using loop read file, want read specific lines, line #26 , #30. there built-in feature achieve this?
thanks
if file read big, , don't want read whole file in memory @ once:
fp = open("file") i, line in enumerate(fp): if == 25: # 26th line elif == 29: # 30th line elif > 29: break fp.close()
note i == n-1
n
th line.
in python 2.6 or later:
with open("file") fp: i, line in enumerate(fp): if == 25: # 26th line elif == 29: # 30th line elif > 29: break
Comments
Post a Comment