eof?

Alex Martelli aleaxit at yahoo.com
Tue Aug 14 17:51:52 EDT 2001


"Cris A. Fugate" <fugate at lucent.com> wrote in message
news:Pine.LNX.4.33.0108141537500.592-100000 at IL0015ACSULLIV3.ih.lucent.com...
> Can't find a convenient way to check for the end of an input file.
> I would like to say something like this where fh.eof would return
> a boolean value for the eof condition. How is this done, or is
> there another way? TIA
>
> fh = open("file", "r")
> while (not fh.eof):
>    fh.readline()

There are several ways.  Best overall, today (Python 2.1):

    for line in fh.xreadlines():
        process(line)


Alex






More information about the Python-list mailing list