Python – FileNotFoundError: [Errno 2] No such file or directory: ‘y’ [closed]

I’m not trying to be rude or anything, but the error message is definitely very clear. The error itself FileNotFoundError means that a file you requested was not found in the location you told the program to look. If I were to have a folder with the files a, b and c in it, and I asked to open y, I would expect this error. Because y is not a, b or c.

Assuming from the code you provided the value of the_file is "y" then you’re asking Python to look in the location around where you execute the program from (I’m assuming Python behaves this way). If you do in fact have a file called y then I suggest you move it to the location where you want to execute from or move to that location and execute the Python code (whichever best suits your needs).

Leave a Comment