From the comments it seems that this line is very large. If there is too much data to fit into memory conveniently, one approach is to process the data from the file line by line as follows:
N = ... with open('data.txt') as inf: for count, line in enumerate(inf, 1): if count == N:
Using enumerate () gives you the index and value of the object you are iterating over and you can specify the starting value, so I used 1 (instead of the default value of 0)
The advantage of using with is that it automatically closes the file for you when you are finished, or if you encounter an exception.
Levon source share