0

I am completely new to Python 3 and I'm very interested in learning how to open CSV data from websites. When I save a CSV to my local drive and run the following code it runs without issue:

import csv

with open("total_cases.csv") as covid:
    covid_dict = csv.DictReader(covid)
    for row in covid_dict:
        print(row["Canada"])

I assumed that I could extrapolate this code to replace the local file name with the URL from which I downloaded that original CSV instead:

import csv

with open("https://covid.ourworldindata.org/data/ecdc/total_cases.csv") as covid:
    covid_dict = csv.DictReader(covid)
    for row in covid_dict:
        print(row["Canada"])

When I do this, however, I obtain a no such directory or file error. Is there a trick I can use to make Python scan a CSV from a URL as opposed to from the local drive?

  • 1
    Did you try putting anything like `python read file internet` or `python download file` into a search engine? – Karl Knechtel May 28 '20 at 01:54
  • Hello @KarlKnechtel, I can appreciate that you are quite advanced and this is probably very easy for you... but I am genuinely trying to learn programming and am looking for help. The link that was provided to a duplicate question isn't really a duplicate. Would you be able to assist with my specific question? If not, I would really be grateful if you can open up my question again. Although very basic for many people I am sure, I would really like to learn. – Kevin Ali May 29 '20 at 00:01
  • The only difference between what you've already shown you're able to do, and what you want to do, is reading a file from the internet. The duplicate link explains exactly how to do that. – Karl Knechtel May 29 '20 at 02:21

0 Answers0