iterate start at second row in file not first

Falcolas garrickp at gmail.com
Tue May 20 14:48:46 EDT 2008


On May 20, 12:34 pm, notnorweg... at yahoo.se wrote:

> how do i jump the first step there? i dont want to iterate the first
> row...how do i start at the second?

To simply bypass the first line, do a readline() on the file object
before starting to process the file. To filter out particular lines
throughout the file, you can either do a check in the for loop and
continue if it is true, or create a generator which filters out
unwanted content.

untested:

fd = open(some_file)
fi = (x for x in fd if (x.search(':') < 0))
for line in fi:
    pass

It gets a bit more complicated if you want to actually split on
sentences, not lines.



More information about the Python-list mailing list