运维网's Archiver
论坛
›
Python
› python倒读文件
afox123
发表于 2018-8-8 12:22:42
python倒读文件
with open('log.txt','rb') as fd:
for i in fd:
offs=-5
while True:
fd.seek(offs,2)
data=fd.readlines()
if len(data) > 1:
print('文件的最后一行是%s' %(data[-1].decode('utf-8')))
break
offs*=2
页:
[1]
查看完整版本:
python倒读文件