I am trying to clear data from large files .txton the Internet using Python 3.
The data that I receive is reliably located in the first 2000 characters of the text, and the download / download time makes downloading the entire file quite expensive.
Is there a way to load only the first N characters or lines from a remote file?
Something like the following:
import urllib.request
with open(urllib.request.urlopen(myurl)) as myfile:
head= [next(myfile) for x in range(10)]
print(head)
source
share