0

I've got a txt file of about 720000 rows and what I want to do is to read only one line from this file. The file look like this:

0000010010010010010101
0100100101010100001110
0101001001010010100101
1010101010101000000111
...

So I try to use this code:

 f = open("1.txt", "r")
 line= f.readline(5)
 f.close()
 print line

But instead of reading the line number 5, I get as output the first 5 characters of the first line.

Hyperion
  • 2,515
  • 11
  • 37
  • 59

1 Answers1

3

You can use linecache standard library , give the file name and the line number to read as arguments. [Documentation]

fifthline = linecache.getline(`filename`, 5)
Anand S Kumar
  • 88,551
  • 18
  • 188
  • 176