-2

I want to open a github raw CSV file with the Python built-in open() function but I am getting a [Errno 2] No such file or directory error:

url = 'https://raw.githubusercontent.com//snowformatics//Bioinformatics//master//python_course092021//test_data//test.csv'

data = open(url, 'r')

With Pandas everything works:

df1 = pd.read_csv(url)

I want to avoid Pandas or urlopen because I am using it for a course and want to stick to built-in open() function. Any way to open an url with the Python built-in open() function?

honeymoon
  • 2,400
  • 5
  • 34
  • 43

1 Answers1

0

You can use this, it's a built-in library.

NOTE: you cant use open to access web-data

import urllib.request

file_url = 'https://raw.githubusercontent.com//snowformatics//Bioinformatics//master//python_course092021//test_data//test.csv'

file_name = 'test.csv'

urllib.request.urlretrieve(file_url, file_name)
Hanna
  • 1,071
  • 1
  • 2
  • 14
  • I want to use the Python built-in open() function, thanks. – honeymoon Jun 07 '22 at 07:07
  • 1
    `urllib` is part of the standard Python library and does not require any separate installation of a third-party package. There is no reason not to use it. – blhsing Jun 07 '22 at 07:27