4

Possible Duplicate:
python: how to jump to a particular line in a huge text file?

I'm trying to read various lines out of a large (250Mb) file.

The header tells me where certain parts are, i.e. the history subsection of the file starts at byte 241817341.

So is there a way to read the file only starting at that byte, without having to go through the rest of the file first? Something like:

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

Is that sort of thing feasible?

4

1 回答 1

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

f.seek(4)
print f.readline()
>>> o, world!
于 2012-06-26T23:33:53.777 回答