Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### jump_to_a_text_file_line_addr.py
- # You can't jump ahead without reading in the file at least once, since you don't know where the line breaks are. You could do something like:
- # Read in the file once and build a list of line offsets
- line_offset = []
- offset = 0
- for line in file:
- line_offset.append(offset)
- offset += len(line)
- file.seek(0)
- # Now, to skip to line n (with the first line being line 0), just do
- file.seek(line_offset[n])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement