Reading CSV Files from the web

How to retrieve the CSV file as a string from the web.

from urllib.request import urlopen
from io import StringIO
import csv
data = urlopen('https://people.sc.fsu.edu/~jburkardt/data/csv/addresses.csv').read().decode('ascii','ignore')
dataFile = StringIO(data)
dReader = csv.DictReader(dataFile)

print(dReader.fieldnames)

for row in dReader:
    print(row)

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *