读取日志最后一行的实现方法:
1.txt内容
2017-1-23 falkdfj0coveenfhi;'aodjf 2017-1-24 adsfl;jka;dfixnjkla;f;jkncvhjfnbhdjknb 2017-1-25 aldkfjlakdfjosjjiangjiangkdjf;kj;flkjdlkjlkajf 2017-1-25 aldkfjlakdfjosjjiangjiangkdjf;kj;flkjdlkjlkajf 2017-1-25 aldkfjlakdfjosjjiangjiangkdjf;kj;flkjdlkjlkajf 2017-1-25 aldkfjlakdfjosjjiangjiangkdjf;kj;flkjdlkjlkajf 2017-1-25 aldkfjlakdfjosjjiangjiangkdjf;kj;flkjdlkjlkajf65 2017-1-25 aldkfjlakdfjosjjiangjiangkdjf;kj;flkjdlkjlkajf65 2017-1-25 aldkfjlakdfjosjjiangjiangkdjf;kj;flkjdlkjlkajf56 2017-1-25 aldkfjlakdfjosjjiangjiangkdjf;kj;flkjdlkjlkajf324 2017-1-25 aldkfjlakdfjosjjiangjiangkdjf;kj;flkjdlkjlkajf435 2017-1-25 aldkfjlakdfjosjjiangjiangkdjf;kj;flkjdlkjlkajf234 2017-1-25 aldkfjlakdfjosjjiangjiangkdjf;kj;flkjdlkjlkajf34 2017-1-25 aldkfjlakdfjosjjiangjiangkdjf;kj;flkjdlkjlkajf454 2017-1-25 023i;kjglkcojngkdjf;kj;flkjdlkjlkajf343 2017-1-25 aldkfjlakdfjosjsdfwsdjf;kj;flkjdlkjlkajf21312 2017-1-25 aladf;alksjd02fx90g;kj;flkjdlkjlkajf123123 2017/1/26 aing;lkfj; ojiangjiang';lkj;l,mn
代码如下:
f = open('1.txt','rb') for i in f: offer = -10 while 1: f.seek(offer,2) data = f.readlines() if len(data) > 1: print("last lines is :%s"%data[-1].decode("utf8")) break offer*=2