python中backward_Python - Backward File Reading

Python - Backward File Reading

当我们正常读取文件时,从文件开头逐行读取内容。 但是有些情况下我们想先读取最后一行。 例如,文件中的数据底部有最新记录,我们希望首先读取最新记录。 为了达到此要求,我们使用以下命令安装所需的包以执行此操作。pip install file-read-backwards

但是在向后读取文件之前,让我们逐行读取文件的内容,以便我们可以在向后阅读后比较结果。with open ("Path\GodFather.txt", "r") as BigFile:

data=BigFile.readlines()

# Print each line

for i in range(len(data)):

print "Line No- ",i

print data[i]

当我们运行上面的程序时,我们得到以下输出 -Line No- 0

Vito Corleone is the aging don (head) of the Corleone Mafia Family.

Line No- 1

His youngest son Michael has returned from WWII just in time to see the wedding of Connie Corleone (Michael's sister) to Carlo Rizzi.

Line No- 2

All of Michael's family is involved with the Mafia, but Michael just wants to live a normal life. Drug dealer Virgil Sollozzo is looking for Maf

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值