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!
Maybe using instead
Beware of the slash versus backslash problem also.
Note that
is useful to know the current directory.
Shouldn't it be a raw string -
r"C:\Users\etc"
?... or the explicit string