蟒蛇.从中间点(按字节)逐行读取文件

Edd*_*heB 3 python file

可能重复:
python:如何跳转到一个巨大的文本文件中的特定行?

我正在尝试从大型(250Mb)文件中读取各种行.

标题告诉我某些部分在哪里,即文件的历史子部分从字节241817341开始.

那么有没有办法只从该字节开始读取文件,而不必先浏览文件的其余部分?就像是:

file = open(file_name,'r')
history_line = file.readline(241817341)
while history_line != 'End':
    history_line = file.readline()
    [Do something with that line]
Run Code Online (Sandbox Code Playgroud)

那种事情可行吗?

Ant*_*t P 7

f.seek(0)
print f.readline()
>>> Hello, world!

f.seek(4)
print f.readline()
>>> o, world!
Run Code Online (Sandbox Code Playgroud)