How to ignore the first line of the text read from a file

Paul Rubin http
Thu Aug 28 16:09:30 CEST 2008


rurpy at yahoo.com writes:
> If the OP needs line numbers elsewhere in the
> code something like the following would work.
> 
> infile = open(fileName, 'r')
> for lineNumber, line in enumerate (infile):
>     # enumerate returns numbers starting with 0.
>     if lineNumber == 0: continue
>     print line,

This also seems like a good time to mention (untested):

   from itertools import islice

   for line in islice(infile, 1, None):
      print line,



More information about the Python-list mailing list