I am having great difficulty getting python 3.4 to recognize a path or text file on a windows 8 system. I have tried a variety of different approaches but get the similar errors (which likely implies something simple regarding the syntax).
The file itself is located in the same folder as the script file trying to open it: C:\Users\User\Desktop\Python stuff\Data.txt
for simplicity, the simplest means to access the file (at least that I know of) is
f=open
These lines were coded as:
f = open("Data.txt", "r")
and
f = open("C:/Users/User/Desktop/Python stuff/Data.txt", "r")
but return the error:
Traceback (most recent call last):
File "C:\Users\User\Desktop\Python stuff\Testscript.py", line 3, in <module>
f = open("C:/Users/User/Desktop/Python stuff/Data.txt", "r")
FileNotFoundError: [Errno 2] No such file or directory: 'C:/Users/User/Desktop/Python stuff/Data.txt'
This is an old question, but thought I'd throw my two cents in anyway.
I had this same issue. I was using VS Code for my IDE, and had the folder setting to a folder above where I had the file. This obviously was the issue. Once I opened the folder in VScode where the code and the text file were both located I was able to open the file with no issues.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With