(original) (raw)
*** fileinput.py Wed Jul 23 09:19:03 2003 --- myfileinput.py Wed Jul 23 09:23:05 2003 *************** *** 82,88 **** import sys, os __all__ = ["input","close","nextfile","filename","lineno","filelineno", ! "isfirstline","isstdin","FileInput"] _state = None --- 82,88 ---- import sys, os __all__ = ["input","close","nextfile","filename","lineno","filelineno", ! "isfirstline","islastline","isstdin","FileInput"] _state = None *************** *** 162,167 **** --- 162,176 ---- raise RuntimeError, "no active input()" return _state.isfirstline() + def islastline(): + """ + Returns true the line just read is the last line of its file, + otherwise returns false. + """ + if not _state: + raise RuntimeError, "no active input()" + return _state.islastline() + def isstdin(): """ Returns true if the last line was read from sys.stdin, *************** *** 337,342 **** --- 346,354 ---- def isfirstline(self): return self._filelineno == 1 + def islastline(self): + return self._bufindex == len(self._buffer) + def isstdin(self): return self._isstdin *************** *** 351,358 **** for line in input(args, inplace=inplace, backup=backup): if line[-1:] == '\n': line = line[:-1] if line[-1:] == '\r': line = line[:-1] ! print "%d: %s[%d]%s %s" % (lineno(), filename(), filelineno(), ! isfirstline() and "*" or "", line) print "%d: %s[%d]" % (lineno(), filename(), filelineno()) if __name__ == '__main__': --- 363,371 ---- for line in input(args, inplace=inplace, backup=backup): if line[-1:] == '\n': line = line[:-1] if line[-1:] == '\r': line = line[:-1] ! print "%d: %s[%d]%s%s %s" % (lineno(), filename(), filelineno(), ! isfirstline() and "*" or "", ! islastline() and "^" or "", line) print "%d: %s[%d]" % (lineno(), filename(), filelineno()) if __name__ == '__main__':