how do I "peek" into the next line?

Fredrik Lundh fredrik at pythonware.com
Tue Dec 14 00:46:57 CET 2004


les_ander at yahoo.com wrote:

>I should have also said that I am using the same file handle.
> So suppose the file handle is fp
> then I read some lines from fp and I hand it over to other
> functions that read other things from fp (in an ordered manner).

another part of your program?  so why not use one of the wrappers
that people have posted?  or just pass the extra line to the next step:

    while 1:
        s = file.readline()
        if not s or s[0] == "#":
            break
        # process lines that belong to section 1

    while 1:
        # process lines that belong to section 2
        if not s or s[0] == "#":
            break
        s = file.readline()

    (etc)

</F> 






More information about the Python-list mailing list