Python cant find file

Python cant find file

This is an old question, but thought Id 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.

When using Windows you want to keep in mind that if you name the file data.txt the file will actually be data.txt.txt, however Windows will show it as data.txt because windows hides the file extensions by default. This option can be changed by following the steps in the first comment.

If you then search data.txt there really is no such file.

Python cant find file

  • for f = open(Data.txt, r)

Make sure your .py and .txt files are in the same directory.

  • for f = open(C:/Users/User/Desktop/Python stuff/Data.txt, r)

I think the space in Python stuff is messing things up.

Update: I just tried this out .. seems to be fine with the space actually.

>>> [i for i in open(/Users/pk-msrb/projects/temp/temp es/temp.txt)]
[1n, 2n, 3n, n]

Leave a Reply

Your email address will not be published. Required fields are marked *