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,355
  • 11
  • 34
  • 56

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
  • 82,977
  • 18
  • 174
  • 164