Graceful handling of first line

Mel Wilson mwilson at the-wire.com
Fri Oct 8 12:04:24 EDT 2004


In article <mailman.4563.1097227579.5135.python-list at python.org>,
Egbert Bouwman <egbert.list at hccnet.nl> wrote:
>A file is too large to fit into memory.
>The first line must receive a special treatment, because
>it contains  information about how to handle the rest of the file.
>
>Of course it is not difficult to test if you are reading the first line
>or another one, but it hurts my feelings to do a test which by definition
>succeeds at the first record, and never afterwards.
>Any suggestions ?

        f = file("lines.txt", "rt")
        first_line_processing (f.readline())
        for line in f:
            line_processing (line)

ought to work.

        Regards.        Mel.



More information about the Python-list mailing list