readline - Ignore lines while reading a file in Python -



readline - Ignore lines while reading a file in Python -

the first part of programme requires me read in file ignore first few lines. file read in like:

blah blah blah character(%% example) more blah.

my question is, how read lines in file ignore %% , every line above it?

just read , dump lines til find 1 want. file iterator internal buffering, differently depending on want afterwards.

with open('somefile') f: # ignore first line "%%" line in f: if "%%" in line: break # process rest line in f: do_amazing_stuff(line)

or perhaps

with open('somefile') f: # ignore first line "%%" while true: line = f.readline() if not line or "%%" in line: break # process rest do_amazing_stuff(f.read())

python readline

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -