Python Forum
Using online python for course, How do I open a File that's a link?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using online python for course, How do I open a File that's a link?
#1
Hi there!

I am doing a (beginner) python course online that allows us to use python in a jupyter notebook. I am trying to open a file that looks like a link and is a .csv.

links={'GDP':'https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/PY0101EN/projects/coursera_project/clean_gdp.csv',\
       'unemployment':'https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/PY0101EN/projects/coursera_project/clean_unemployment.csv'}
#GDP = links["GDP"]
#print(GDP)
with open('https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/PY0101EN/projects/coursera_project/clean_gdp.csv', 'r') as GDPFile:
    GDPData = GDPFile.read()
    print(GDPData)
print(GDPFile.closed)
print(GDPData)
And I get this error:
Error:
FileNotFoundError Traceback (most recent call last) <ipython-input-14-53937e55fa2e> in <module> 4 #GDP = links["GDP"] 5 #print(GDP) ----> 6 with open('https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/PY0101EN/projects/coursera_project/clean_gdp.csv', 'r') as GDPFile: 7 GDPData = GDPFile.read() 8 print(GDPData) FileNotFoundError: [Errno 2] No such file or directory: 'https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/PY0101EN/projects/coursera_project/clean_gdp.csv'
So I downloaded the file to my local drive and tried it this way:

links={'GDP':'https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/PY0101EN/projects/coursera_project/clean_gdp.csv',\
       'unemployment':'https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/PY0101EN/projects/coursera_project/clean_unemployment.csv'}
#GDP = links["GDP"]
#print(GDP)
with open('C:\Users\Amanda\Documents\Coursera IBM Data Science Certification\Python for Data Science and AI\clean_gdp.csv', 'r') as GDPFile:
    GDPData = GDPFile.read()
    print(GDPData)
print(GDPFile.closed)
print(GDPData)
However I get this error:
Error:
File "<ipython-input-11-59f1f16be3ed>", line 6 with open('C:\Users\Amanda\Documents\Coursera IBM Data Science Certification\Python for Data Science and AI\clean_gdp.csv', 'r') as GDPFile: ^ SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
Am I missing something? Does the file need to be saved in the notebook or under the same project? I'm using python on a data platform, IBM cloud.
Reply


Messages In This Thread
Using online python for course, How do I open a File that's a link? - by WhatsupSmiley - Mar-19-2020, 09:14 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Open/save file on Android frohr 0 349 Jan-24-2024, 06:28 PM
Last Post: frohr
  file open "file not found error" shanoger 8 1,197 Dec-14-2023, 08:03 AM
Last Post: shanoger
  How can i combine these two functions so i only open the file once? cubangt 4 897 Aug-14-2023, 05:04 PM
Last Post: snippsat
  I cannot able open a file in python ? ted 5 3,450 Feb-11-2023, 02:38 AM
Last Post: ted
  testing an open file Skaperen 7 1,410 Dec-20-2022, 02:19 AM
Last Post: Skaperen
  Run a Function?: Trouble with Online Python Course webmanoffesto 3 1,021 Aug-18-2022, 10:14 PM
Last Post: deanhystad
  I get an FileNotFouerror while try to open(file,"rt"). My goal is to replace str decoded 1 1,425 May-06-2022, 01:44 PM
Last Post: Larz60+
  How do I link the virtual environment of that project to the 3.9.2 version of python? Bryant11 1 1,396 Feb-26-2022, 11:15 AM
Last Post: Larz60+
  I can't open a link with Selenium in Python jao 0 1,419 Jan-30-2022, 04:21 AM
Last Post: jao
  Dynamic File Name to a shared folder with open command in python sjcsvatt 9 6,087 Jan-07-2022, 04:55 PM
Last Post: bowlofred

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020