- 1

How do i skip strings using open()?

f =("filename.txt", "r") print(f.readline(x))

3rd Feb 2022, 12:50 AM
Ace Brown
Ace Brown - avatar
4 Answers
+ 2
Ace Brown if you know how far you want to skip or exactly where you want to start reading next, you can use the seek() method. https://www.tutorialspoint.com/JUMP_LINK__&&__python__&&__JUMP_LINK/file_seek.htm Otherwise, you can just read the strings and not use them until you get to the desired place in the file.
3rd Feb 2022, 5:17 AM
Brian
Brian - avatar
+ 2
I would use something like this if I knew exactly what line I want to start with: x = int(input()) import itertools with open('yourfile.txt') as f: line_to_begin = f.readlines()[x:]
3rd Feb 2022, 5:40 AM
BroFar
BroFar - avatar
0
Let's say I want to begin after the first 5 characters would I have to do those things ? X = int(input(?) ) Import intertools With open ('filename.txt) as f: Lin_to_begin = f.readline()[5:] ??
4th Feb 2022, 5:31 PM
Ace Brown
Ace Brown - avatar
0
Ace Brown based on the rewrite yes that should skip over the first 5 strings not characters I used x as int(input()) as a means to point to how many strings you wanted to skip.
4th Feb 2022, 10:08 PM
BroFar
BroFar - avatar