Python获得操作日志的最后几行记录

该方法一般用于获得操作日志的最后几行记录

 1 #!/usr/bin/env python
 2 # -*- coding:utf-8 -*-
 3 f = open('seek.txt', 'rb')
 4 
 5 
 6 def get_file_last_line(accept_file):
 7     offs = -10
 8     while True:
 9         accept_file.seek(offs, 2)
10         data = accept_file.readlines()
11         if len(data) > 1:
12             print('文件最后一行:%s' % (data[-1].decode('utf-8')))
13             break
14         offs *= 2
15 
16 
17 get_file_last_line(f)
seek(-x,2)

猜你喜欢

转载自www.cnblogs.com/chenyanbin/p/10294682.html
今日推荐