Ask Your Question

Revision history [back]

Importing File using open()

Hello, I am trying to use the following code to access a file that is not in the same folder as my .ipynb note book. However, it is giving me an error message.

Code:

  alldata = open("C:/Users/tahah/Desktop/hihi.txt", "r")    
  print(alldata.read())

output:

  FileNotFoundError                         Traceback (most recent call last)
  /tmp/ipykernel_1888/1727300002.py in <module>
  ----> 1 alldata = open("C:/Users/tahah/Desktop/hihi.txt", "r")
        2 print(alldata.read())
  FileNotFoundError: [Errno 2] No such file or directory: 'C:/Users/tahah/Desktop/hihi.txt'

I have no idea how to fix this. Is anyone able to help? I'm just testing a txt file, but my goal is to be able to open a csv file. (I wanted to mention that in case it changes anything.)

Thanks in advance!

click to hide/show revision 2
retagged

Importing File using open()

Hello, I am trying to use the following code to access a file that is not in the same folder as my .ipynb note book. However, it is giving me an error message.

Code:

  alldata = open("C:/Users/tahah/Desktop/hihi.txt", "r")    
  print(alldata.read())

output:

  FileNotFoundError                         Traceback (most recent call last)
  /tmp/ipykernel_1888/1727300002.py in <module>
  ----> 1 alldata = open("C:/Users/tahah/Desktop/hihi.txt", "r")
        2 print(alldata.read())
  FileNotFoundError: [Errno 2] No such file or directory: 'C:/Users/tahah/Desktop/hihi.txt'

I have no idea how to fix this. Is anyone able to help? I'm just testing a txt file, but my goal is to be able to open a csv file. (I wanted to mention that in case it changes anything.)

Thanks in advance!