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.

classification
Title: new function 'islastline' in fileinput
Type: enhancement Stage: resolved
Components: None Versions:
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Add fileinput.islastline()
View: 968063
Assigned To: Nosy List: ajaksu2, edhi, rhettinger
Priority: normal Keywords:

Created on 2003-07-23 07:49 by edhi, last changed 2022-04-10 16:10 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
fileinput.diff edhi, 2003-07-23 07:49
Messages (3)
msg53949 - (view) Author: Edouard Hinard (edhi) Date: 2003-07-23 07:49
a function 'islastline' is missing to fileinput module.
when that function exists, it is possible to perform an
action at the end of a file like in:

for line in fileinput.input():
   processline(line)
   if fileinput.lastline():
      processfile()


Without this function, the same script looks like:

for line in fileinput.input():
   if fileinput.isfirstline() and fileinput.lineno() != 1:
      processfile()
   processline(line)
processfile()
msg53950 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2004-06-15 12:09
Logged In: YES 
user_id=80475

Reclassifying as a feature request.

I'm -0 on complicating this venerable interface.   Also, I
find it unnatural for the inside of a loop to be able to
ascertain whether it is in its final iteration.  The closest
approximation is the for-else clause which is vary rarely
used in normal python programming.  While the OP was able to
sketch a use case, it involved only saving a couple of lines
over what can be done with the existing API.

P.S. There is a less buggy version of the patch at 
www.python.org/sf/968063
msg81710 - (view) Author: Daniel Diniz (ajaksu2) * (Python triager) Date: 2009-02-12 02:56
Issue 968063 has better patch, use case and discussion.
History
Date User Action Args
2022-04-10 16:10:10adminsetgithub: 38911
2009-02-12 02:56:48ajaksu2setstatus: open -> closed
nosy: + ajaksu2
messages: + msg81710
resolution: duplicate
superseder: Add fileinput.islastline()
stage: resolved
2003-07-23 07:49:10edhicreate