Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if this is last line in file

Tags:

python

logging

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

like image 884
Jens Avatar asked Oct 18 '13 09:10

Jens


1 Answers

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
like image 53
NPE Avatar answered Sep 30 '22 07:09

NPE