读取文件(日志文件)当中的最后一行内容

 1 f = open('日志', 'rb')
 2 for i in f:
 3     offs = -10
 4     while True:
 5         f.seek(offs, 2)
 6         data = f.readlines()
 7         if len(data) > 1:
 8             print('文件的最后一行是%s'%(data[-1].decode('utf-8')))
 9             break
10         offs *= 2
11 
12 f.close()

 http://www.cnblogs.com/linhaifeng/articles/5984922.html

posted @ 2018-04-23 21:05  banshaohuan  阅读(136)  评论(0)    收藏  举报