I have a large csv file of the client and shared via a url to download and I want to download it line by line or by bytes and I want to limit only for 10 entries.
I have the following code which will download the file, but i want here to download only the first 10 entries from the file, I don't want the full file.
#!/usr/bin/env python
import requests
from contextlib import closing
import csv
url = "https://example.com.au/catalog/food-catalog.csv"
with closing(requests.get(url, stream=True)) as r:
f = (line.decode('utf-8') for line in r.iter_lines())
reader = csv.reader(f, delimiter=',', quotechar='"')
for row in reader:
print(row)
I don't know much about contextlib, how it will work with with in Python.
Can anyone help me here, it would be really helpful, and thanks in advance.