Jens
Jens

Reputation: 329

Check if this is last line in file

I'm currently working on a log script with time,value entries.

I use the script as follows:

./parsy.py < log

and in the script I loop over the lines with

for line in sys.stdin:

Is there an easy way to check if the current line is the last one of the input, because I have the save the time of this line as the total time the log ran.

I could update this total time every line, but that's not that efficient...

Thanks in advance

Upvotes: 5

Views: 3450

Answers (1)

NPE
NPE

Reputation: 500377

If extracting the time is as expensive as you say, you could do something like:

line = None
for line in sys.stdin:
  # ...
if line is not None:
  # `line' contains the last line; extract the time etc

Upvotes: 6

Related Questions