简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM