首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >python倒读文件

python倒读文件

作者头像
py3study
发布于 2020-01-14 16:13:53
发布于 2020-01-14 16:13:53
2.7K0
举报
文章被收录于专栏:python3python3
代码语言:javascript
复制
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
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019/08/09 ,如有侵权请联系 cloudcommunity@tencent.com 删除
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档