阅读背景:

python读取文件最后n行

来源:互联网 
# -*- coding:utf8-*-
import os
import time
import datetime
import math
import string

def get_last_line(inputfile) :
  filesize = os.path.getsize(inputfile)
  blocksize = 1024
  dat_file = open(inputfile, 'r')
  last_line = ""
 
  lines =  dat_file.readlines()
  count = len(lines)
  if count>60:
      num=60
  else:
      num=count
  i=1;
  lastre = []
  for i in range(1,(num+1)):
      if lines :
          n = -i
          last_line = lines[n].strip()
          #print "last line : ", last_line
          dat_file.close()
          #print i
          lastre.append(last_line)
  return lastre
#获取最后一行的结果
re = get_last_line('../update/log/rtime/rtime20130805.log')
print len(re)
for n in re:
    strlist = n.split('    ')
    
    if strlist[1] == 'ok' and string.atoi(strlist[2])>1000:
         print '数据条数正常'
         print 'OK'
    else:
         print '数据太少,检查发邮件'# -*- coding:utf8-*-
import os
import time
impo



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: