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 nth 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

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -