This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author relm
Recipients
Date 2004-06-15.18:42:38
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
Logged In: YES 
user_id=1058331

The OP's use case was too simplified to convey
the usefulness of fileinput.islastline().  It does not
just save a couple of lines.  I am attaching a "wc" or
"word count" program to demonstrate.  Note the following
problems with the current work-around:

1. Instead of doing end-of-file processing at the end of
   a file, we must do it at the beginning of the *next*
   file.

2. Useful functions such as fileinput.filelineno() and
   fileinput.filename() now refer to the *wrong* file,
   so now we need to manually keep track of these values
   ourselves.

3. Perhaps a minor point, but this work-around only works
   at the *beginning* of the loop instead of the end.  It
   feels somewhat awkward.

4. End-of-file processing must occur both in the loop and
   once outside.  A function avoids code duplication, but
   to refer to variables in the loop, they must be passed
   into and out of the function (6 in, 2 out for the "wc"
   example... maybe keyword arguments would have helped).

5. Most important is readablility.  It's not obvious that
   `fileinput.isfirstline() and fileinput.lineno() != 1`
   means we are the end of the (previous!) file.  Using
   `fileinput.islastline()` would be much clearer.

And not that it is a reason, but Perl and Ruby solve
this with an `eof` function and `eof?` method,
respectively.
History
Date User Action Args
2007-08-23 15:38:03adminlinkissue968063 messages
2007-08-23 15:38:03admincreate