remove header line when reading/writing files

timaranz at timaranz at
Fri Oct 12 02:28:20 CEST 2007

On Oct 12, 12:23 pm, Tim Chase <python.l... at> wrote:
> Forgot the enumerate call of all things
> > for zipfile in filelist:
> >    for i, line in enumerate(gzip.Gzipfile(zipfile,'r')):
> >            if i: outfile.write(line)
> Some days, I'm braindead.
> -tkc

I would move the 'if' test outside the loop :

for zipfile in filelist:
    zfiter = iter(gzip.Gzipfile(zipfile,'r'))  # ignore header line
    for i, line in enumerate(fziter):

I'm not sure if the iter(...) is required.  This will raise a
StopIteration exception if zipfile is empty.


More information about the Python-list mailing list